'Compare when was last time cronjob run
Background: I'm currently working alongside a FaaS provider that allows us to run in our app a Scheduled Trigger, basically it allows us to run a method on a schedule. The problem is they only give us 3 options: hour, week, year. That means that I can't run a method 4 times a day, 6 hours intervals.
I started thinking about implementing this logic with cron expression
const sixHourCron = new CronJob("0 */6 * * *", () => setScheduledTriggerInterval);
The function setScheduledTriggerInterval
calls an api and verifies user status. This is also the function that gets called each hour by implementing the Scheduled Trigger as referred above. But I only want the function to run if it didn't run within the last 6 hours.
Is there a way of having something like this:
const setScheduledTriggerInterval = () => {
//check last time function ran with global initialized crontime/cronjob?
if 6 hours have passed
run the job
else return and do nothing
}
Note: I have to use the Scheduled Trigger functionality so timeout or intervals are unfortunately not an option
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|