Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Brace/delete old dates cron #69

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
"@langchain/community": "^0.3.22",
"@langchain/core": "^0.3.22",
"@langchain/google-vertexai-web": "^0.1.2",
"@langchain/langgraph": "^0.2.31",
"@langchain/langgraph-sdk": "^0.0.31",
"@langchain/langgraph": "^0.2.39",
"@langchain/langgraph-sdk": "^0.0.36",
"@mendable/firecrawl-js": "^1.10.1",
"@octokit/rest": "^21.0.2",
"@slack/web-api": "^7.7.0",
Expand Down
53 changes: 53 additions & 0 deletions scripts/crons/clear-old-scheduled-dates.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import "dotenv/config";
import { Client } from "@langchain/langgraph-sdk";
import { DEFAULT_TAKEN_DATES, SCHEDULE_DATES_KEY, SCHEDULE_DATES_NAMESPACE, TAKEN_DATES_KEY, type TakenScheduleDates } from "../../src/agents/generate-post/nodes/schedule-post/find-date.js";

/**
* Clear the store of old scheduled dates. Runs daily at 1AM PST
* and deletes all scheduled dates older than 2 days.
*/
async function clearOldScheduledDates() {

Check failure on line 9 in scripts/crons/clear-old-scheduled-dates.ts

View workflow job for this annotation

GitHub Actions / Unit Tests (ubuntu-latest, 18.x)

'clearOldScheduledDates' is declared but its value is never read.

Check failure on line 9 in scripts/crons/clear-old-scheduled-dates.ts

View workflow job for this annotation

GitHub Actions / Unit Tests (ubuntu-latest, 20.x)

'clearOldScheduledDates' is declared but its value is never read.
const client = new Client({
apiUrl: process.env.LANGGRAPH_API_URL,
// apiUrl: "http://localhost:54367",
});

const takenDates: TakenScheduleDates = (await client.store.getItem(SCHEDULE_DATES_NAMESPACE, SCHEDULE_DATES_KEY))?.value?.[TAKEN_DATES_KEY] || DEFAULT_TAKEN_DATES;

takenDates.p1 = takenDates.p1.filter((date: Date) => {
const twoDaysAgo = new Date();
twoDaysAgo.setDate(twoDaysAgo.getDate() - 2);
return new Date(date) > twoDaysAgo;
});
takenDates.p2 = takenDates.p2.filter((date: Date) => {
const twoDaysAgo = new Date();
twoDaysAgo.setDate(twoDaysAgo.getDate() - 2);
return new Date(date) > twoDaysAgo;
});
takenDates.p3 = takenDates.p3.filter((date: Date) => {
const twoDaysAgo = new Date();
twoDaysAgo.setDate(twoDaysAgo.getDate() - 2);
return new Date(date) > twoDaysAgo;
});

await client.store.putItem(SCHEDULE_DATES_NAMESPACE, SCHEDULE_DATES_KEY, {
[TAKEN_DATES_KEY]: takenDates
});
}

async function createCron() {

Check failure on line 38 in scripts/crons/clear-old-scheduled-dates.ts

View workflow job for this annotation

GitHub Actions / Unit Tests (ubuntu-latest, 18.x)

'createCron' is declared but its value is never read.

Check failure on line 38 in scripts/crons/clear-old-scheduled-dates.ts

View workflow job for this annotation

GitHub Actions / Unit Tests (ubuntu-latest, 20.x)

'createCron' is declared but its value is never read.
const client = new Client({
apiUrl: process.env.LANGGRAPH_API_URL,
// apiUrl: "http://localhost:54367",
});

const res = await client.crons.create("clear_old_scheduled_dates", {
schedule: "0 1 * * *",
config: {
configurable: {
slackChannelId: "ADD_SLACK_CHANNEL_ID_HERE",
},
},
});
console.log(res);
}
4 changes: 2 additions & 2 deletions scripts/generate-demo-post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { TEXT_ONLY_MODE } from "../src/agents/generate-post/constants.js";
* Social Media Agent works.
*/
async function invokeGraph() {
const link = "https://blog.langchain.dev/customers-appfolio/";
const link =
"https://open.substack.com/pub/diamantai/p/nexus-ai-the-revolutionary-research";

const client = new Client({
apiUrl: process.env.LANGGRAPH_API_URL || "http://localhost:54367",
Expand All @@ -24,7 +25,6 @@ async function invokeGraph() {
// By default, the graph will read these values from the environment
// [TWITTER_USER_ID]: process.env.TWITTER_USER_ID,
// [LINKEDIN_USER_ID]: process.env.LINKEDIN_USER_ID,

// This ensures the graph runs in a basic text only mode.
// If you followed the full setup instructions, you may remove this line.
[TEXT_ONLY_MODE]: true,
Expand Down
26 changes: 26 additions & 0 deletions scripts/get-interrupts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import "dotenv/config";
import { Client } from "@langchain/langgraph-sdk";

async function getInterrupts() {
const client = new Client({
apiUrl: process.env.LANGGRAPH_API_URL,
});

const newLinksArr: string[] = [
// Add your new links here
];

const { thread_id } = await client.threads.create();
await client.runs.create(thread_id, "ingest_data", {
input: {
links: newLinksArr,
},
config: {
configurable: {
skipIngest: true,
},
},
});
}

getInterrupts();
4 changes: 2 additions & 2 deletions scripts/get-scheduled-runs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ async function sendPendingRunsToSlack(messageString: string) {

async function getScheduledRuns() {
const client = new Client({
// apiUrl: process.env.LANGGRAPH_API_URL,
apiUrl: "http://localhost:54367",
apiUrl: process.env.LANGGRAPH_API_URL,
// apiUrl: "http://localhost:54367",
});
const threads = await client.threads.search({
metadata: {
Expand Down
47 changes: 0 additions & 47 deletions scripts/invoke-graph.ts

This file was deleted.

Loading
Loading