'Prevent the same job to run twice node-cron

I'm working with node and typescript, using node-cron 2.0 to schedule a background operation to run every hour.

  cron.schedule("0 0 * * * *", () => {
     purgeResponsesSurveys();
   });

I'm concerned about what happens if the method doesn't finish within 1 hour since I don't want two instances of my method to run at the same time.

What are the best practices to prevent the scheduler from invoking the function purgeResponsesSurveys if it is already running from the previous hourly invocation?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source