I have config elysia cron job for my schedule job. I have build using bun. I create utils for my job every time i want to have scheduler for my specific time to run. But when I call and separate the elysia only with unique path. The scheduler still running and not to stop the cron when i manually stop. below is my code:
import cron from '@elysiajs/cron';
import Elysia from 'elysia';
import { update as updateStatus, select as selectScheduler } from '../db/scheduler';
import { runK6 } from '../cmd/k6';
interface Scheduler {
name: string;
time: string;
runningPath: any;
}
export const schedulerUtils = (schedule: Scheduler) => {
const app = new Elysia();
app.listen(3000);
app.use(
cron({
name: schedule.name,
pattern: schedule.time,
run: async () => {
const { platform, spec } = await getScheduler(schedule.name);
console.log('start scheduler ', spec);
if (platform === 'k6') {
await runK6(JSON.parse(spec as string));
}
console.log('stop scheduler ', spec);
},
})
);
app.get('/stop/:name', ({ params: { name }, store: { cron } }) => {
cron[name].stop();
updateStatus({ name, status: 0 });
return `Stop heartbeat ${name}`;
});
};
const getScheduler = async (name: string) => {
const res = await selectScheduler(name);
return res;
};
export const schedulerName = (spec: any) => {
return (
spec.projectName.toLocaleLowerCase().split(' ').join('_') +
'_' +
spec.name.toLocaleLowerCase().split(' ').join('_') +
'_' +
spec.path.toLocaleLowerCase().split('/').join('_')
);
};
Any solution kindly suggestion or provided the tutorial how to using with elysia cron. Thank beforehand.
Hope the question will get the solution and how to use the elysia cron.