Running Macro when sheduled time was missed.

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
pfischer
Junior Coder
Posts: 21
Joined: Wed Jul 23, 2014 2:07 pm

Running Macro when sheduled time was missed.

Post by pfischer » Sat Apr 08, 2017 7:18 am

Dear forum,
I have an apparently simple question to which I however do not find a solution. In my scripting, it happens from time to time that a script does not run properly run and stops in executing due to external issues. When I then go in the program and solve the problem, I sometimes forget to reset the timer and log out. Because we really have a lot of scripts running this unfortunately happen from time to time. Then the program waits for 24 hour until the sheduled time is reached at the next day.

In the advanced options, there is a checkbox for exactly this when windows is restarted. I am looking for a similar option but without that window is restarted. An option like: run script if sceduled was missed (even without a restart of windows).

Has anyone an idea?

Thanks
Philipp

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1352
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Running Macro when sheduled time was missed.

Post by Dorian (MJT support) » Mon Apr 10, 2017 9:57 pm

If I'm understanding correctly, this may be a workaround.

So you're running a script which encounters an external problem, and cannot complete it's tasks until you fix the external problem. You then want it to run again once the problems are fixed.

How about this :

1. Make the script write to an output file whenever it has successfully completed.
2. Schedule that script to run more often than once per day, by using the Repeat option in scheduler.
3. At the very beginning of the script, make it read the file we created in step 1. If a successful log entry exists for today, abort. If not, continue.

Would that do the job?
Yes, we have a Custom Scripting Service. Message me or go here

mightycpa
Automation Wizard
Posts: 343
Joined: Mon Jan 12, 2004 4:07 pm
Location: Vienna, VA

Re: Running Macro when sheduled time was missed.

Post by mightycpa » Tue Apr 11, 2017 5:37 am

If you're changing the script to fix the problem, you could write another little script that would monitor the file dates of your script file(s), and when a script is saved and updated, the monitor script could pop up an alert or send you a text to remind you to reset the timer and/or run it in production.

If you have a lot of scripts that you're managing, you might also consider writing a job monitor, which would keep track of planned vs. actual script runs and notify you when a success is missing.
"A facility for quotation covers the absence of original thought." - Lord Peter Wimsey

pfischer
Junior Coder
Posts: 21
Joined: Wed Jul 23, 2014 2:07 pm

Re: Running Macro when sheduled time was missed.

Post by pfischer » Fri Apr 14, 2017 7:00 am

Dear mightycps and Dorian,
thanks for your reply.

Dorian,
your solution works if the script only runs one time a day. My scripts run every hour and therefore, if the time was missed, wait until the next day. So this solution will not work for my applications. Anyway thanks a lot.

Mightycpa,
I already realised your idea with an extrenal checkfile which remindes me. Your idea to have a script which monitors planned vs. actual script runs sounds a good idea. I have somethink like this already with the produced output files but it only gives me an email and does not automatically restart the script.
Can you tell me how I access the planned execution time of a certein script by another script and modify it. If this is possible, I can create a very small script which continuousl checks the planned scripts and comprate it to the actual time and if it is past due for more than lets say 5 min, I can rescwdule it. This would perfectly work if I can access the planned time of a script from outside.

Thanks a lot for this idea
Philipp

mightycpa
Automation Wizard
Posts: 343
Joined: Mon Jan 12, 2004 4:07 pm
Location: Vienna, VA

Re: Running Macro when sheduled time was missed.

Post by mightycpa » Sat Apr 15, 2017 4:08 am

I'd suggest some kind of common ini file where every script checks in with that and writes an entry when it finishes.. and maybe when it begins too.

So for example, let's say you have 3 scripts. One.scp runs once a day, two.scp twice, three.scp thrice.

I'd keep track of regular start time, how long it runs, and the interval, so you have data set up for the start time. You might even get the script to keep track of the last n times to keep this average run time statistic current, in case it varies over time for whatever reason.

You might have to keep track of start times manually, or, if you can decipher the data in the macros12.dat file, you should be able to read that file and calculate when the next start time is. Maybe Marcus will tell you how it works, but it doesn't look too hard. You could use this data to predict the next start time.

When it runs, a script would update the last time it started, and in the finished section, it would put "running". When it ends, it would replace "running" by recording a timestamp (and maybe a new duration).

Your monitor script might run once every 30 minutes, determine if a script ran, should have run, should be finished, whatever.

Your ini file might look like this, and you can see there's a problem with Two.scp and your script could text you or however you want to handle it.

[Schedule]
#script,scheduled time, interval, amount (for timeadd)
One_1,14:00,M,30
Two_1,12:15,H,2
Two_2,0:15,H,2
Three_1,3:20,M,60
Three_2,11:20,M,60
Three_3,7:20,M,60

[Start]
#script,last started
One_1:4/14/2017 2:00:36 PM
Two_1,4/14/2017 12:15:04 PM
Two_2,4/13/2017 0:15:03 AM
Three_1,4/14/2017 3:20:36 PM
Three_2,4/14/2017 11:20:36 PM
Three_3,4/14/2017 7:20:36 AM

[End]
#script, last finished
One_1:4/14/2017 2:31:36 M
Two_1, running
Two_2,4/13/2017 2:19:03 AM
Three_1,4/14/2017 4:22:36 PM
Three_2,4/14/2017 11:50:36 PM
Three_3,4/14/2017 12:20:36 PM
"A facility for quotation covers the absence of original thought." - Lord Peter Wimsey

pfischer
Junior Coder
Posts: 21
Joined: Wed Jul 23, 2014 2:07 pm

Re: Running Macro when sheduled time was missed.

Post by pfischer » Sat Apr 15, 2017 12:34 pm

Dear mightycpa
your idea to read out the sheduled start time of a certain scripts from the macros12.dat file was excellent. I created a small macro which runs every 15 min and looks in the macro12.dat file and extracts the scheduled run time of the script I want to check. I then compare if this sheduled time is after the actual time of the system and if so, it writes an e-mail to alert me.

If this run's good over the next days, I will automatize this so that the macro updatesthe sheduled starttime in the macro12.dat file for the macro if the sheduled time was missed for some reason.

Using an additional textfile where all macros I want to check are listed one per line by their names, I can even perform a loop over all macros and sequentially check all macros for missed sheduled run.

This is perfectly what I wanted to have. Many thanks for this idea to read out the sheduled time in the macro12.dat file. :D
Philipp

pfischer
Junior Coder
Posts: 21
Joined: Wed Jul 23, 2014 2:07 pm

Re: Running Macro when sheduled time was missed.

Post by pfischer » Mon Apr 17, 2017 12:05 pm

Dear mightycps and Dorian,
yesterday I wrote that the solution for checking if a script is out of time by reading the sheduled time in the macro12.dat file is the solution for my problem. Even though this is still the case, I now face another problem with the file macro12.dat itself.

This file seems not to be updated regularily. When I read the sheduled time this is often not the time which is shown in the frontend (which is the correct time when the macro is running next). So the macro12.dat file sometimes contains old time information and the real time when the macro is sheduled is hold in the memory??

I could not really figure out when the macro12.dat file is updated. This seems in my case to be every 6 to 7 hours but at least always at 24:00 hours in the night and from then on at least for a few hours my scripts works perfectly. However, somewhen in the morning the macro12.dat files seem not to be updated any more.

When I open the script manually and save it again, then the macro12.dat is updated.

So, seem to me that there is something wrong with writing back the sheduled time in the macro12.dat file???

Thanks for your help in this issue.

Best
Philipp

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