Possible to kill macro after set duration? - SOLVED
Moderators: Dorian (MJT support), JRL
Possible to kill macro after set duration? - SOLVED
I'm new to Macro Scheduler, but have found this to be an incredibly easy to use tool.
I have written a pretty complicated macro that controls a JRE - Java Webstart App. This JRE App is less than perfect. As a result, I can get random hangs & random error windows. If I stop the macro & re-run it, it usually will work just fine. This if fine while I am infront of the computer, but once I put this into production, I need this to be much more bullet-proof.
What's the best way of adding in "If 120 seconds goes by, without progressing to the next line, kill macro & restart"? I've looked around for several hours & haven't found exactly what I am looking for (don't know if I need to look more into doing something with OnEvent or look more into doing something around the Log Files).
Thank you in advance for any help you can offer.
-Joe
I have written a pretty complicated macro that controls a JRE - Java Webstart App. This JRE App is less than perfect. As a result, I can get random hangs & random error windows. If I stop the macro & re-run it, it usually will work just fine. This if fine while I am infront of the computer, but once I put this into production, I need this to be much more bullet-proof.
What's the best way of adding in "If 120 seconds goes by, without progressing to the next line, kill macro & restart"? I've looked around for several hours & haven't found exactly what I am looking for (don't know if I need to look more into doing something with OnEvent or look more into doing something around the Log Files).
Thank you in advance for any help you can offer.
-Joe
Last edited by headgeek on Tue Feb 07, 2017 3:09 pm, edited 1 time in total.
Re: Possible to kill macro after set duration?
I posted a possible solution HERE a couple of months ago. Of course its generic and would need to be modified to suit your needs. Fundamentally you'd throw out the Loop portion of my script, reset the first line to whatever time you want the timeout to be (in seconds) and place the line Timer>StartTime at appropriate places in your script. The Timer>StartTime line will reset the timer to zero. If the script does not reach a line where the timer is reset to zero in less than timeout seconds, the ResultEvent subroutine is started. You would change the ResultEvent to code that will close and restart your script. If you need help with that let us know.
So your script would look something like:
So your script would look something like:
Code: Select all
Let>TimePeriod=120
Timer>StartTime
OnEvent>Custom,EventTimer,TimedOut,ResultEvent
SRT>EventTimer
Timer>EndTime
Let>TotalTime={(%EndTime%-%StartTime%)/1000}
If>%TotalTime%>%TimePeriod%
Let>TimedOut=True
EndIf
END>EventTimer
SRT>ResultEvent
//Start process that will wait for this script to exit
//then restart this script
//Do any closing processes needed before exit
Exit>0
END>ResultEvent
//Stuff in your current script
Timer>StartTime
//Stuff in your current script
Timer>StartTime
//Stuff in your current script
Timer>StartTime
//Stuff in your current script
Timer>StartTime
//Etc
Re: Possible to kill macro after set duration?
Thank you for you help! This is a great way to solve this problem!
I have added in some additional instructions, that will take a screenshot of where the computer was when it timed out, and then email it out. I got this working, but for some reason, it does it twice. Any idea of what would cause this?
My initial impression is that the script times out and
1.jumps into the subroutine "ResultEvent" (which is capture a screenshot and email it out), then it goes to Exit>0
2.before it exits, it tries to complete the step that it was working on when time ran out
3.redoes "ResultEvent", and then closes.
Any ideas is appreciated!
I have added in some additional instructions, that will take a screenshot of where the computer was when it timed out, and then email it out. I got this working, but for some reason, it does it twice. Any idea of what would cause this?
My initial impression is that the script times out and
1.jumps into the subroutine "ResultEvent" (which is capture a screenshot and email it out), then it goes to Exit>0
2.before it exits, it tries to complete the step that it was working on when time ran out
3.redoes "ResultEvent", and then closes.
Any ideas is appreciated!
Re: Possible to kill macro after set duration?
I see what you mean. I created a sample and it ran the sub twice before closing also. Solved it by adding a variable to flag whether the routine had already run. See example below
Code: Select all
Let>timerFlag=0
Let>TimePeriod=120
Timer>StartTime
OnEvent>Custom,EventTimer,TimedOut,ResultEvent
SRT>EventTimer
Timer>EndTime
Let>TotalTime={(%EndTime%-%StartTime%)/1000}
If>%TotalTime%>%TimePeriod%
Let>TimedOut=True
EndIf
END>EventTimer
SRT>ResultEvent
If>TimerFlag=0
Let>TimerFlag=1
//Start process that will wait for this script to exit
//then restart this script
//Do any closing processes needed before exit
Exit>0
EndIf
END>ResultEvent
//Stuff in your current script
Timer>StartTime
//Stuff in your current script
Timer>StartTime
//Stuff in your current script
Timer>StartTime
//Stuff in your current script
Timer>StartTime
//Etc
Re: Possible to kill macro after set duration?
Perfect, Thank you!
I can't begin to tell you how much time I spent looking at the log file and reviewing the code. I was positive that I messed up the original code by adding in my additional instructions (as by itself it worked fine, as it was basically two exits)
That fix is so simple, yet something I wouldn't have come up with. Adding this to my knowledge bank.
Again, Thank you!
I can't begin to tell you how much time I spent looking at the log file and reviewing the code. I was positive that I messed up the original code by adding in my additional instructions (as by itself it worked fine, as it was basically two exits)
That fix is so simple, yet something I wouldn't have come up with. Adding this to my knowledge bank.
Again, Thank you!
Follow Up Question - How to Pause Timer
Just a quick follow up question: I have one step in that could take way longer.
What's the best way to pause the timer?
Only Idea that I have is to give the timer a crazy high second count.
Let>TimePeriod=12000000000
after the step is completed, I will put it back
Let>TimePeriod=120
Any other ideas?
What's the best way to pause the timer?
Only Idea that I have is to give the timer a crazy high second count.
Let>TimePeriod=12000000000
after the step is completed, I will put it back
Let>TimePeriod=120
Any other ideas?
Re: Possible to kill macro after set duration? - SOLVED
Sounds like it will work and only adds two lines of code. I would call that THE solution.
Re: Possible to kill macro after set duration? - HELP
Hello
i know this post was solved and closed but i need a little help understanding it i am using notepad as an example.
i should have 2 possible end results. option 1 text in notepad is found and script is complete with message>process complete. if text is not found i would like the notpad to be closed and the process restarted.
what is wrong with how i am using the below script.
i know this post was solved and closed but i need a little help understanding it i am using notepad as an example.
i should have 2 possible end results. option 1 text in notepad is found and script is complete with message>process complete. if text is not found i would like the notpad to be closed and the process restarted.
what is wrong with how i am using the below script.
Code: Select all
Let>timerFlag=0
Let>TimePeriod=20
Timer>StartTime
OnEvent>Custom,EventTimer,TimedOut,ResultEvent
SRT>EventTimer
Timer>EndTime
Let>TotalTime={(%EndTime%-%StartTime%)/1000}
If>%TotalTime%>%TimePeriod%
Let>TimedOut=True
EndIf
END>EventTimer
SRT>ResultEvent
//Start process that will wait for this script to exit
//then restart this script
//Do any closing processes needed before exit
Message>Process not complete
wait>5
//Do any closing processes needed before exit
CloseWindow>notepad*
wait>1
Exit>0
END>ResultEvent
//Stuff in your current script
RunProgram>C:\Windows\notepad.exe
wait>2
SendText>macro scheduler is the best
wait>1
Timer>StartTime
//Stuff in your current script
GetTextInit
GetWindowTextEx>Untitled - Notepad,result
WaitScreenText>macro scheduler is the best
wait>2
Timer>StartTime
//Stuff in your current script
Message>process completed!! :)
wait>5
Timer>StartTime
Re: Possible to kill macro after set duration? - SOLVED
First your notepad script has no reason to fail so no likelihood of matching your "text is not found" scenario. But mainly the script I presented is a vague outline and shouldn't be taken so literally.i know this post was solved and closed but i need a little help understanding it...
The premise to use a script like this is that you have a program that sometimes fails or sometimes fails to produce a given result in a predefined time frame. If you have this situation then you would introduce elements of my script into specific locations within your script. headgeek needed to restart his script in the condition that it did not accomplish a given task within a set amount of time. When that situation occurred the custom OnEvent> would trigger and a second script would be started. That second script would wait for the primary script to close and then restart the primary script.
I have an idea for a notepad example. I'll see if I can get that written and posted later today.
Re: Possible to kill macro after set duration? - SOLVED
just wanted to update the post i did mange to solve the issue. I had the 2 codes mixed so there was these 2 lines missing from my code
If you have the Endif after the Exit>0 line the script is not exited but it stops so putting the Endif before the Exit>0 line works great.
Code: Select all
If>TimerFlag=0
Let>TimerFlag=1
If you have the Endif after the Exit>0 line the script is not exited but it stops so putting the Endif before the Exit>0 line works great.
Code: Select all
Let>timerFlag=0
Let>TimePeriod=120
Timer>StartTime
OnEvent>Custom,EventTimer,TimedOut,ResultEvent
SRT>EventTimer
Timer>EndTime
Let>TotalTime={(%EndTime%-%StartTime%)/1000}
If>%TotalTime%>%TimePeriod%
Let>TimedOut=True
EndIf
END>EventTimer
SRT>ResultEvent
If>TimerFlag=0
Let>TimerFlag=1
//Start process that will wait for this script to exit
//then restart this script
//Do any closing processes needed before exit
EndIf
Exit>0
END>ResultEvent
//Stuff in your current script
Timer>StartTime
//Stuff in your current script
Timer>StartTime
//Stuff in your current script
Timer>StartTime
//Stuff in your current script
Timer>StartTime
//Etc
Re: Possible to kill macro after set duration? - SOLVED
Hello,
I have been using JRL`s Custome onevent and it works great it does the job of restarting the script if for any reason the application you are controlling hangs and a given amount of time passes. However i is it possible to use to custom time based onevent handlers?
e.g
/////////////////////Restart Script If No Progress///////////////////////
Let>timerFlag=0
Let>TimePeriod=30
Timer>StartTime
OnEvent>Custom,EventTimer,TimedOut,ResultEvent
SRT>EventTimer
Timer>EndTime
Let>TotalTime={(%EndTime%-%StartTime%)/1000}
If>%TotalTime%>%TimePeriod%
Let>TimedOut=True
EndIf
END>EventTimer
SRT>ResultEvent
If>TimerFlag=0
Let>TimerFlag=1
//Start process that will wait for this script to exit
//then restart this script
//Do any closing processes needed before exit
Message>Script Did Not Complete Successfully
wait>5
Endif
// Exit>0
END>ResultEvent
/////////////////////////////////////////////////////////////////////////
Let>timerFlag=0
Let>TimePeriod=15
Timer>MyTriggerSub
OnEvent>Custom,EventtTimerr,TimedOut,ResulttEventt
SRT>EventtTimerr
Timer>EndTime
Let>TotalTime={(%EndTime%-%MyTriggerSub%)/1000}
If>%TotalTime%>%TimePeriod%
Let>TimedOut=True
EndIf
END>EventtTimerr
SRT>ResulttEventt
If>TimerFlag=0
Let>TimerFlag=1
//Start process that will wait for this script to exit
//then restart this script
//Do any closing processes needed before exit
SkipLabel>option B
Endif
// Exit>0
END>ResulttEventt
///////////////////////////////////////////////////
While>a=0
Let>b=b+1
Let>tag=tags_%b%
Pos>id="lst-ib",tag,1,a
EndWhile
Timer>MyTriggerSub
/////////////////////////////////////////////////
Label>option B
Timer>StartTime
IEWaitNew>IE[1]
Timer>StartTime
With the above example Timer>MyTriggerSub is triggered and since Timer>MyTriggerSub sends you to Label>Option B and since there is no new IE opened Timer>StartTime should kick in but it does not any ideas to possible solutions.
Thank you
I have been using JRL`s Custome onevent and it works great it does the job of restarting the script if for any reason the application you are controlling hangs and a given amount of time passes. However i is it possible to use to custom time based onevent handlers?
e.g
/////////////////////Restart Script If No Progress///////////////////////
Let>timerFlag=0
Let>TimePeriod=30
Timer>StartTime
OnEvent>Custom,EventTimer,TimedOut,ResultEvent
SRT>EventTimer
Timer>EndTime
Let>TotalTime={(%EndTime%-%StartTime%)/1000}
If>%TotalTime%>%TimePeriod%
Let>TimedOut=True
EndIf
END>EventTimer
SRT>ResultEvent
If>TimerFlag=0
Let>TimerFlag=1
//Start process that will wait for this script to exit
//then restart this script
//Do any closing processes needed before exit
Message>Script Did Not Complete Successfully
wait>5
Endif
// Exit>0
END>ResultEvent
/////////////////////////////////////////////////////////////////////////
Let>timerFlag=0
Let>TimePeriod=15
Timer>MyTriggerSub
OnEvent>Custom,EventtTimerr,TimedOut,ResulttEventt
SRT>EventtTimerr
Timer>EndTime
Let>TotalTime={(%EndTime%-%MyTriggerSub%)/1000}
If>%TotalTime%>%TimePeriod%
Let>TimedOut=True
EndIf
END>EventtTimerr
SRT>ResulttEventt
If>TimerFlag=0
Let>TimerFlag=1
//Start process that will wait for this script to exit
//then restart this script
//Do any closing processes needed before exit
SkipLabel>option B
Endif
// Exit>0
END>ResulttEventt
///////////////////////////////////////////////////
While>a=0
Let>b=b+1
Let>tag=tags_%b%
Pos>id="lst-ib",tag,1,a
EndWhile
Timer>MyTriggerSub
/////////////////////////////////////////////////
Label>option B
Timer>StartTime
IEWaitNew>IE[1]
Timer>StartTime
With the above example Timer>MyTriggerSub is triggered and since Timer>MyTriggerSub sends you to Label>Option B and since there is no new IE opened Timer>StartTime should kick in but it does not any ideas to possible solutions.
Thank you