How to schedule dynamic function with cron job?

后端 未结 6 1910
無奈伤痛
無奈伤痛 2021-01-02 06:02

I want to know how I can schedule a dynamic(auto populated data) function to auto run everyday at saved time?

Let\'s say I have a form that once the button is clicke

6条回答
  •  有刺的猬
    2021-01-02 06:48

    I am suggesting you create Cron Entries dynamically through a wrapper script which configure the cron entry to run your particular function when you actually wanted it to run.

    For your specific case here Below is what I would suggest :

    1. Create a wrapper script And schedule it in Cron to run every Second.
    2. This wrapper script will talk to MySQL and fetch the time at which a specific function is to run.
    3. Then it will Dynamically create a Cron Entry to run that function at that specific retrieved timestamp. You can dynamically add and remove the Cron Entry using the shell script. Please see references below for details.
    4. Once your function is completed, There should be some indication like status stored somewhere maybe in your DB, or some file, so that the wrapper can get/know the status and remove the respective cron entry.

    References
    1. Create Cron Using Bash
    crontab -l | { cat; echo "0 0 0 0 0 some entry"; } | crontab -
    2. Delete/Automate Cron
    crontab -l -u | grep -v | crontab -

提交回复
热议问题