locked
Restarting scheduled task that has failed RRS feed

  • Question

  • I have a scheduled task set up.  I set the task with the option to restart the task every 30 minutes for the next 2 hours if the task failed.  My task failed (returned with an error code) but my task never restarted.  Can someone tell me why this is?

     

    Thanks

    Bob

    Friday, December 30, 2011 8:36 PM
    Avatar of Bob Nona
    Bob Nona
    95
    Points
    Top 15
    Bob Nona
    Joined Oct 2009

    1

    7

    95 Points

Answers

  • If you have for example a script set to run at an interval of time, and that task runs the script but the script doesn't run properly and gives back an error code, then the problem is with the script not the task scheduler. The task scheduler sees the script succesfuly ran so there is no need to restart the task.

    Can you please post the error code?

    In the mean time please be sure to check the following articles released by Microsoft:

    http://technet.microsoft.com/en-us/library/cc721846.aspx - Troubleshooting Task Scheduler

    http://support.microsoft.com/kb/951246 - A scheduled task does not run as expected

    http://technet.microsoft.com/en-us/library/dd851678.aspx - Configure a Scheduled Task Item

     

    Hope it helps.


    MCTS - Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    Monday, January 2, 2012 2:19 AM
    Avatar of Marius Ionut Ene
    IdealStaffs Consulting
    7,848 Points
  • Hi Bob

     

    If “If the Task Fails, Restart every…” is selected, The Task Scheduler will only re-run the task if the task failed to start. In this case, the script already started, so the Task scheduler thought that the task already run. The script’s failure can't let the Task Scheduler repeat the task.

     

    Don't know how to repeat a failed script. Maybe let the script run with a higher frequency?

     

    Thanks

    Wednesday, January 4, 2012 7:26 AM
    Avatar of Boo_MonstersInc
    Boo_MonstersInc
    14,255
    Points
    Top 0.5
    Boo_MonstersInc
    Joined Dec 2011

    2

    4

    12

    Monsters Inc.
    14,255 Points

All replies

  • If you have for example a script set to run at an interval of time, and that task runs the script but the script doesn't run properly and gives back an error code, then the problem is with the script not the task scheduler. The task scheduler sees the script succesfuly ran so there is no need to restart the task.

    Can you please post the error code?

    In the mean time please be sure to check the following articles released by Microsoft:

    http://technet.microsoft.com/en-us/library/cc721846.aspx - Troubleshooting Task Scheduler

    http://support.microsoft.com/kb/951246 - A scheduled task does not run as expected

    http://technet.microsoft.com/en-us/library/dd851678.aspx - Configure a Scheduled Task Item

     

    Hope it helps.


    MCTS - Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    Monday, January 2, 2012 2:19 AM
    Avatar of Marius Ionut Ene
    IdealStaffs Consulting
    7,848 Points
  • Hello

     

    It seems the problem is with the task itself rather than Task Scheduler. You may paste the error code you received here.

     

    Also, do you see any errors in the SCHEDLGU.TXT in C:\Windows\Tasks folder?

     

    Thanks

    Cheers

    Tuesday, January 3, 2012 6:59 AM
    Avatar of Boo_MonstersInc
    Boo_MonstersInc
    14,255
    Points
    Top 0.5
    Boo_MonstersInc
    Joined Dec 2011

    2

    4

    12

    Monsters Inc.
    14,255 Points
  • Maybe I'm not understanding the "If the Task Fails, Restart every" and what this entails.  My script is trying to FTP to a remote site.  The service is not available on the remote site at the time on the remote site.  So I get an exception in my script (I expect this and want this to occur).  So I thought that "If the Task Fails, Restart every" meant that if my task failed, as denoted by getting an error code from my script, that I could set it up to restart.

    So I guess there are two things here, first, what does "If the Task Fails, Restart every" really do?

    Second, is there a way to fire off the script again, if it fails (i.e. FTP service not available) after a delay of say 30 minutes, using the Task Scheduler.

     

    Bob

    Tuesday, January 3, 2012 2:15 PM
    Avatar of Bob Nona
    Bob Nona
    95
    Points
    Top 15
    Bob Nona
    Joined Oct 2009

    1

    7

    95 Points
  • Hi Bob

     

    If “If the Task Fails, Restart every…” is selected, The Task Scheduler will only re-run the task if the task failed to start. In this case, the script already started, so the Task scheduler thought that the task already run. The script’s failure can't let the Task Scheduler repeat the task.

     

    Don't know how to repeat a failed script. Maybe let the script run with a higher frequency?

     

    Thanks

    Wednesday, January 4, 2012 7:26 AM
    Avatar of Boo_MonstersInc
    Boo_MonstersInc
    14,255
    Points
    Top 0.5
    Boo_MonstersInc
    Joined Dec 2011

    2

    4

    12

    Monsters Inc.
    14,255 Points
  • It is possible to "restart" the task if it failes.

     1. Use following code in the batch script to create a system error event:
     
    eventcreate /ID 100 /SO "Your Script Name" /L APPLICATION /T ERROR /D "Your failure reason"



     2. Create a new task with a trigger that monitors the system events and filter for the category and ID you just added in the batch. The action of this task is the batch again. This task should be delayed by one minute, so that the same batch is not startet twice!

    Be careful not to create an undefinite loop.

    Hope that helps!
    Friday, July 22, 2016 12:46 PM
  • I know this is an old post, but just in case others searched for this problem, below is a workaround.

    The issue is the actions are only considered to fail if they cannot be started.  This is pretty dumb, but the scheduler doesn't care about the results of the actions.

    One workaround is to add an action at the end to run something like "ok.exe" and then have your other actions either create "ok.exe" (good result) or delete it. (bad result)

    This way when the Task Scheduler goes to run the last action it will fail to start it (if you had removed it, because your previous action failed).  This will cause the Task Scheduler to go ahead and Queue up your Task for a restart based on the restart settings on the Scheduled Task.

    PS: To create a dummy ok.exe, I usually just copy c:\windows\system32\clip.exe c:\mytask\ok.exe


    - Tolga

    Tuesday, May 26, 2020 4:43 AM
    Avatar of Tolga Balci
    codeuwp
    10 Points