Search code examples
javascriptnode.jscron

Cronjob Javascript, how to fire job limited times? ( set counter and max limit )


I'm new to Cronjob and looking for a way to fire it with interval but only 5 times. Im firing an API call with cron and do not want to loop it. Is it possible to set a counter and max limit of how many times cron has been executed? or is there another better way of making delayed API calls with nodejs 5 times during 5 min ?


Solution

  • I am not sure if crontab allows to have count. Rather you can write a wrapper program which will be called by the cron job. The wrapper can store the count of how many times the api is called.(save count to a file/database). Based on the count, wrapper can decide whether to call api or not.Then schedule your wrapper cron to run every 5 mins(whatever the interval that you need).