Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added logic to run cron job
Browse files Browse the repository at this point in the history
Paribesh01 committed Oct 14, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 95fad42 commit a47cc0e
Showing 2 changed files with 18 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/actions/corn.ts
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);
}
});
}
});
};
2 changes: 2 additions & 0 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { startCronJob } from '@/actions/corn';
import Faqs from '@/components/Faqs';
import HeroSection from '@/components/hero-section';
import { JobLanding } from '@/components/job-landing';
import Testimonials from '@/components/Testimonials';

const HomePage = async () => {
startCronJob();
return (
<div>
<HeroSection />

0 comments on commit a47cc0e

Please sign in to comment.