Run Cron Job every 45 minutes with Node-Cron

前端 未结 8 771
别那么骄傲
别那么骄傲 2020-12-25 13:58

I\'m using node-cron to run scheduled jobs. I want the jobs to run every 45 minutes, but its acting strangely

Here\'s the pattern I\'m using

\'00 */45

相关标签:
8条回答
  • 2020-12-25 14:40

    There is no direct way to do this. However, we can get the result by intercepting the schedule using a shell command within the target script.

    First, run the script at every 15 minutes:

    */15 * * * * <target_script>
    

    Then, within the target_script, place the following code before actual codes:

    #!/bin/sh
    
    # Exit except at 0:45, 1:30, 2:15, 3:00, 3:45 etc
    
    if ! echo "((`date +%-H`*60)+`date +%-M`)/45" | bc -l | grep "\.0*$" &> /dev/null;
    then exit 1;
    fi
    
    # Your actual code goes here;
    
    0 讨论(0)
  • 2020-12-25 14:44

    You can refer to cronr, it supports all the macro pattern and provides online demo cronr -- online demo

    0 讨论(0)
提交回复
热议问题