-
Notifications
You must be signed in to change notification settings - Fork 456
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
feat: added logic to run cron job
1 parent
95fad42
commit a47cc0e
Showing
2 changed files
with
18 additions
and
6 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 |
---|---|---|
@@ -1,10 +1,20 @@ | ||
// lib/cron.ts | ||
import cron from 'node-cron'; | ||
import { updateExpiredJobs } from './job.action'; | ||
|
||
cron.schedule('0 * * * *', async () => { | ||
try { | ||
await updateExpiredJobs(); | ||
} catch (error) { | ||
console.error('Error updating expired jobs:', error); | ||
let cronJobInitialized = false; | ||
|
||
export const startCronJob = () => { | ||
if (!cronJobInitialized) { | ||
cronJobInitialized = true; | ||
|
||
// Schedule the job to run at midnight (12:00 AM) every day | ||
cron.schedule('0 0 * * *', async () => { | ||
try { | ||
await updateExpiredJobs(); | ||
} catch (error) { | ||
console.error('Error updating expired jobs:', error); | ||
} | ||
}); | ||
} | ||
}); | ||
}; |
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