forked from langchain-ai/social-media-agent
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcreate-cron.ts
50 lines (46 loc) · 1.44 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
45
46
47
48
49
50
import "dotenv/config";
import { Client } from "@langchain/langgraph-sdk";
import {
SKIP_CONTENT_RELEVANCY_CHECK,
SKIP_USED_URLS_CHECK,
} from "../../src/agents/generate-post/constants.js";
/**
* 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 8 * * *", // Runs at 8:00 AM UTC every day (1AM PST)
config: {
configurable: {
slackChannelId: "ADD_SLACK_CHANNEL_ID_HERE",
maxDaysHistory: 1,
[SKIP_CONTENT_RELEVANCY_CHECK]: true,
[SKIP_USED_URLS_CHECK]: true,
},
},
input: {},
});
console.log("\n\nCreated cron\n\n");
console.dir(res, { depth: null });
const crons = await client.crons.search();
console.log("\n\nAll Crons\n\n");
console.dir(crons, { depth: null });
}
createCron().catch(console.error);