-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added examples and renames file from key-value to tasks-db
- Loading branch information
1 parent
8e86d6b
commit fd06f96
Showing
2 changed files
with
58 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import {KeyValueDB} from "../packages/core/src/core/tasks-db"; | ||
import chalk from "chalk"; | ||
|
||
async function main() { | ||
|
||
const taskDb = new KeyValueDB( | ||
"mongodb://localhost:27017", | ||
"myApp", | ||
); | ||
|
||
await taskDb.connect(); | ||
|
||
// // Store a task | ||
await taskDb.createTask('task_001',{ | ||
_id: "task_001", | ||
type: "ongoing", | ||
scheduledFor: new Date(Date.now() + 1000 * 60 * 60 * 24), // 24 hours from now, | ||
metadata: { description: "Sample task" }, | ||
}); | ||
|
||
// Fetch and execute pending scheduled tasks | ||
const tasks = await taskDb.fetchTasks("scheduled", "pending"); | ||
for (const task of tasks) { | ||
await taskDb.executeTask(task._id); | ||
} | ||
|
||
// Store a message thread | ||
await taskDb.storeMessageThread("thread_001", "user_123", [ | ||
{ | ||
messageId: "msg_001", | ||
content: "Hello!", | ||
timestamp: new Date(), | ||
}, | ||
{ | ||
messageId: "msg_002", | ||
content: "How can I help?", | ||
timestamp: new Date(), | ||
}, | ||
]); | ||
|
||
// Fetch a message thread | ||
const thread = await taskDb.fetchMessageThread("thread_001"); | ||
console.log("Fetched thread:", thread); | ||
} | ||
|
||
// Run the example | ||
main().catch((error) => { | ||
console.error(chalk.red("Fatal error:"), error); | ||
process.exit(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters