0

Currently, I have done the following:

  1. I created one scheduled task which runs daily to get the Scheduled time from Mysql DB for the currentdate and store it into the .txt file

    SELECT workflow_id, DATE_FORMAT(schedule_datetime,'%H:%i')TIMEONLY FROM scheduling_event where DATE(schedule_datetime) = CURDATE()

  2. Created one more scheduled task that runs each 5mins to check if the scheduled time present in the .txt file matches the CURRENT TIME if yes then it calls the scheduled_program.php file.

The issue here is - this is not an efficient way if nothing is scheduled on the current date. So Is there any way to create/update a dynamic scheduled task instead of running each 5mins? ie: the first scheduled task will run and take the scheduled time on the current date then it will create a task based on the scheduled time. if the day ends delete all the scheduled tasks for the day.

Note: Number of the scheduled task is not fixed. imusing Windows 10, php7. I am trying to achieve, run a scheduled_program php file on schedule Date and TIME

O. Jones
  • 103,626
  • 17
  • 118
  • 172
Anu Priya
  • 33
  • 1
  • 1
  • 9
  • The best solution would probably be leaving a database out of this and schedule jobs in cron or other job scheduler directly. However, your description of the use case is too much focused on the technical details, not on what business objective you wanted to achieve. – Shadow Oct 13 '20 at 10:49
  • i am trying to achieve , run a scheduled_program.php file on schedule date&time @Shadow – Anu Priya Oct 13 '20 at 10:53
  • Does this answer your question? [How to create cron job using PHP?](https://stackoverflow.com/questions/18737407/how-to-create-cron-job-using-php) – kewlashu Oct 13 '20 at 10:57
  • Aha. this is not a UNIX `cron` problem, it's a Windows Task Scheduler problem. – O. Jones Oct 13 '20 at 11:16
  • Questions: If you have two workflows scheduled for, say, 07:18, how do you know which runs first? Is it OK if one runs at 07:18 and the next one at 07:20 (after the first one finishes?) Is it OK if the first of them runs at 07:20 and the next one at 07:22, when the first one finishes? How exact do you require your workflow start times to be? What happens if your workflow scheduler fails on the first night of a three-day holiday and no workflows run during that time? – O. Jones Oct 13 '20 at 11:20
  • @AnuPriya if your business case is only `run a scheduled_program.php file on schedule date&time`, then just simply schedule it in cron or any other scheduler! Why do you need to check every 5 minutes for this in a database? – Shadow Oct 13 '20 at 11:29
  • Can you suggest **'any other scheduler'** way to achieve this @Shadow and O.Jones – Anu Priya Oct 13 '20 at 12:11
  • @AnuPriya no, I cannot. 1) your business case and platform are inclear to me 2) asking us to recommend any product is explicitly off topic here on SO. – Shadow Oct 13 '20 at 12:23

1 Answers1

0

It looks like you're trying to solve a problem that's not serious. I guess you don't want to waste your computer's time running a cron job every five minutes if it has nothing to do.

But here's the thing:

  • a cron job
  • that runs a php program
  • that does a single query
  • to retrieve a list of workflows
  • and run them

has negligible cost if you run the cron job every five minutes, or even every single minute, and there are no workflows to run.

On the other hand, debugging and troubleshooting cronjobs is hard, especially in production.

So, I respectfully suggest you keep this system as simple as you possibly can. You will have to explain it over the telephone to somebody in the middle of the night at least once. That's the unfortunate truth of scheduled tasks. The dynamic scheduled task system you propose is not simple.

O. Jones
  • 103,626
  • 17
  • 118
  • 172