How to have the Scheduler retry a task when it has failed with a specific error code?

4

1

I have a cmd file which executes an application (exe) that can return a specific error code in some cases. This cmd is launched by the Scheduler every day.
If it failed with this specific error, I want to be able to reschedule and retry the task every 30mn up to 3 times or for the next 2 hours before giving up until the next day.

How can I pass the error code to the scheduler to have it retry automatically (if at all possible) or how can I create a new temporary fail-over scheduled task from the initial cmd?

It should run mainly on Win2003 and Win2008 servers (x32 or x64).

François

Posted 2010-06-26T01:27:45.750

Reputation: 143

Answers

1

just try to run your command, wait on failure and rerun it. you can use ping to fake a sleep command (or get a sleep.exe from the resource toolkit or hack your own or use vbscript). anyway, just schedule this script daily:

@echo first try here
@if not errorlevel 42 goto end
@ping 127.0.0.1 -w 1000 > NUL

@echo second try here
@if not errorlevel 42 goto end
@ping 127.0.0.1 -w 2000 > NUL

@echo third try here
@if not errorlevel 42 goto end
@ping 127.0.0.1 -w 3000 > NUL

@echo will try again tomorrow

:end
@echo finish %errorlevel%

replace 42with the exit code your are interested in and replace -w 1000 with the time in milliseconds you want to wait between each retry.

akira

Posted 2010-06-26T01:27:45.750

Reputation: 52 754

That's more or less the workaround I had in mind but I am a bit concerned about leaving it ping or sleep for 30mn instead of rescheduling. Any potential drawback with pinging for a big chunk of time? – François – 2010-06-27T22:20:36.917

i do not know. you can also grab a sleep.exe from somewhere, if that makes you feel more comfortable. – akira – 2010-06-27T22:47:48.130

1

Use a script (batch file) to call your application and test the error code and conditionally re-execute it or exit.

Then schedule the script instead of the application.

Mike Fitzpatrick

Posted 2010-06-26T01:27:45.750

Reputation: 15 062