Skip to content

Commit

Permalink
Merge pull request #53 from Giveth/add-cron-job
Browse files Browse the repository at this point in the history
Add cron job
  • Loading branch information
MohammadPCh authored May 21, 2024
2 parents 18c7c16 + 4f57d84 commit c548134
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 5 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/pipeline-develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
git checkout -- .
git pull
docker compose stop devouch squid-db
docker compose rm -v -f devouch squid-db
docker rmi -f $(docker images | grep 'devouch' | awk '{print $3}')
docker volume rm $(docker volume ls | grep 'db-data' | awk '{print $2}')
# docker compose rm -v -f devouch squid-db
# docker rmi -f $(docker images | grep 'devouch' | awk '{print $3}')
# docker volume rm $(docker volume ls | grep 'db-data' | awk '{print $2}')
docker compose up -d --build
27 changes: 27 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@subsquid/typeorm-store": "^1.4.0",
"dotenv": "^16.4.4",
"ethers": "^6.12.1",
"node-cron": "^3.0.3",
"pg": "^8.11.5",
"type-graphql": "^1.2.0-rc.1",
"typeorm": "^0.3.20",
Expand All @@ -30,6 +31,7 @@
"@subsquid/typeorm-codegen": "^1.3.3",
"@types/jest": "^29.5.12",
"@types/node": "^20.11.17",
"@types/node-cron": "^3.0.11",
"jest": "^29.7.0",
"ts-jest": "^29.1.2",
"ts-node": "^10.9.2",
Expand Down
1 change: 1 addition & 0 deletions src/features/import-projects/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const CRON_SCHEDULE = "0 0 * * *"; // UTC
14 changes: 12 additions & 2 deletions src/features/import-projects/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import cron from "node-cron";
import { fetchAndProcessGivethProjects } from "./giveth/helpers";
import { CRON_SCHEDULE } from "./config";

export const task = async () => {
console.log("Importing Projects", new Date());
await fetchAndProcessGivethProjects();
};

export const importProjects = async () => {
try {
console.log("Importing Projects");
await fetchAndProcessGivethProjects();
console.log("Importing Projects has been scheduled.");
cron.schedule(CRON_SCHEDULE, task, {
scheduled: true,
timezone: "UTC",
});
} catch (error) {
console.log("Error", error);
}
Expand Down
3 changes: 3 additions & 0 deletions src/features/import-projects/standalone.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { task } from ".";

task();

0 comments on commit c548134

Please sign in to comment.