Windows scheduler : Wait for first task to complete before starting second task

venkatesh padmanabhan 181 Reputation points
2022-04-04T12:01:38.523+00:00

Hi.
I have a Task setup in windows scheduler. Daily task - scheduled to run at 6 a.m. and has a Repeat task every 8 hours for a duration of 9 hours.
stop all running tasks at end of repetition duration.

The task which starts at 6 a.m. sometimes is long running and might not be finishing at 2 p.m. I want to setup the scheduler in such a way that only when the 6 a.m. task is completed fully, then the second task which is a repeat option should trigger.

How to achieve this in windows scheduler ?

Thanks

Windows for business | Windows Server | User experience | Other
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Limitless Technology 39,926 Reputation points
    2022-04-06T20:43:18.1+00:00

    Hi @venkatesh padmanabhan

    By default, scheduled tasks will be run even if the previous instance of the task is still running. To prevent this, you may use the withoutOverlapping method:

    $schedule->command('emails:send')->withoutOverlapping();

    In this example, the emails: send Artisan command will be run every minute if it is not already running. The withoutOverlapping method is especially useful if you have tasks that vary drastically in their execution time, preventing you from predicting exactly how long a given task will take.

    Here's another example:

    /**  
     * Do not allow the event to overlap each other.  
     *  
     * @return $this  
     */  
    public function withoutOverlapping()  
    {  
        $this->withoutOverlapping = true;  
        return $this->skip(function () {  
            return file_exists($this->mutexPath());  
        });  
    }  
    

    I hope this answers your question.

    ------------

    --If the reply is helpful, please Upvote and Accept as answer--

    1 person found this answer helpful.
    0 comments No comments

  2. Olaf Helper 47,516 Reputation points
    2022-04-04T12:33:06.623+00:00

    Why 2 schedules with one action and not one schedule with two actions; they would run in sequence?


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.