Terminating a scheduled job

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
csim
Newbie
Posts: 3
Joined: Thu Nov 05, 2009 4:22 pm

Terminating a scheduled job

Post by csim » Thu Nov 05, 2009 4:48 pm

Hi,

I am fairly new to Macro Scheduler and real impressed at its functionality. However I am faced with one issue though. I am accessing some websites and pulling data from it. Sometimes, the file is not available or the site changes but my script is still running and excepting something (a wait window et al). I think this messes up my other jobs when they run (or do they). Is there a way before job#2 runs to check and see if job#1 (or any other schedule job is running) to terminate them so job#2 can run cleanly?

Thanks!
--csim

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Nov 05, 2009 5:34 pm

One method I use is have each macro Write to a common file near the start. Before that, however, each macro tests for the existence of the common file and will not start until the file does not exist. Then after the macro completes the last line will delete the common file allowing the next macro to proceed. Something like:

Code: Select all

Label>CheckAtStart
IfFileExists>%Temp_Dir%Common_File.tmp
  Wait>5
  Goto>CheckAtStart
endIf

WriteLn>%Temp_Dir%Common_File.tmp,wres,

//Rest of the Macro

DeleteFile>%Temp_Dir%Common_File.tmp
If the first script is locked up waiting for a window that will never open perhaps you need to include a wait window timeout see help for WaitWindowOpen>.

csim
Newbie
Posts: 3
Joined: Thu Nov 05, 2009 4:22 pm

Post by csim » Thu Nov 05, 2009 9:16 pm

Hi JRL,

Thanks for the suggestion. I do have timeouts in my WaitWindowOpen. I think I may need more extensive error trapping. The issue is, if the website changes without my knowledge, it makes it difficult to predict what will happen. This is not a dependency issue (wait for one job to finish before starting another). I would like to abort any pending job (maybe the website is down or have changed or script went south) before the next one starts.

Thanks! :)

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Nov 05, 2009 11:14 pm

You could create job#1.5 as below. Schedule job#1.5 to run a minute or two before job#2. The script below will close all instances of msched.exe then restart msched.exe. Once Macro Scheduler is restarted the next scheduled job (job#2) should start on its own with no other jobs running. The script will leave a DOS window behind. This could probably be avoided by writing a VBScript version of taskkill msched.exe, writing it to a .VBS file and executing it. Or you could have job#2 close the DOS window.

Code: Select all

IfFileExists>%TEMP_DIR%killmsched.bat
  DeleteFile>%TEMP_DIR%killmsched.bat
EndIf

WriteLn>%TEMP_DIR%killmsched.bat,wresult,taskkill /f /im msched.exe
WriteLn>%TEMP_DIR%killmsched.bat,wresult,%COMMAND_LINE%

Let>RP_WAIT=0
Run>cmd /c %TEMP_DIR%killmsched.bat

csim
Newbie
Posts: 3
Joined: Thu Nov 05, 2009 4:22 pm

Post by csim » Fri Nov 06, 2009 12:00 am

Hi JRL,

Good idea! Instead of attempting to kill a pending job (or two), killing the app would take care of that, but how do I restart msched?

Oops - I think I just stumbled upon a solution in this entire thought process but will need to test it out. How about job 1.5 actually identifying msched application and sending the stop combo key strokes to it (stops any job if running). Not sure what would happen to job 1.5 itself right after it sends the keystrokes.

Thanks,
--csim

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Fri Nov 06, 2009 5:48 am

csim wrote:nstead of attempting to kill a pending job (or two), killing the app would take care of that, but how do I restart msched?
Dick wrote:The script below will close all instances of msched.exe then restart msched.exe.
The batch file created in the previously posted script will close all instances of msched.exe and then open one instance that will not include any running scripts.
csim wrote:Oops - I think I just stumbled upon a solution in this entire thought process but will need to test it out. How about job 1.5 actually identifying msched application and sending the stop combo key strokes to it (stops any job if running). Not sure what would happen to job 1.5 itself right after it sends the keystrokes.
Sending Shift + Esc keystrokes in a script stops the sending script and that's all. It will not stop other scripts. Run the following and you will never see the message "Did the script get here?"

Code: Select all

Press Shift
Press esc
Release shift
MDL>Did the script get here?

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts