generated from langchain-ai/new-langgraphjs-project
-
Notifications
You must be signed in to change notification settings - Fork 141
/
Copy pathcreate-cron.ts
44 lines (40 loc) · 1.15 KB
/
create-cron.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import "dotenv/config";
import { Client } from "@langchain/langgraph-sdk";
/**
* Creates a new cron job in LangGraph for data ingestion.
*
* This function sets up a daily cron job that runs at midnight (00:00) to ingest data.
* It uses the LangGraph Client to create a new cron job with specified configuration
* and then retrieves a list of all existing cron jobs.
*
* @async
* @returns {Promise<void>} A promise that resolves when the cron job is created
* and the list of crons is retrieved
* @throws {Error} If there's an issue creating the cron job or retrieving the list
*
* @example
* ```bash
* yarn cron:create
* ```
*/
async function createCron() {
const client = new Client({
apiUrl: process.env.LANGGRAPH_API_URL,
});
const res = await client.crons.create("ingest_data", {
schedule: "0 0 * * *",
config: {
configurable: {
slackChannelId: "ADD_SLACK_CHANNEL_ID_HERE",
maxDaysHistory: 1,
},
},
input: {},
});
console.log("Created cron");
console.log(res);
const crons = await client.crons.search();
console.log("Crons");
console.log(crons);
}
createCron().catch(console.error);