Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[module] Cron 0.5 - Library for making cron timers


  • Please log in to reply
18 replies to this topic
tonne
  • Members
  • 1654 posts
  • Last active: May 06 2014 06:22 PM
  • Joined: 06 Jun 2006
The question of adding cron scheduling parallel with timers in AutoHotkey has been asked a couple of times (http://www.autohotke...opic.php?t=1123).

This library makes it possible to start multiple cron based timers in your script: Download cron library.

To use it place cron.ahk in your standard or user library (%A_ProgramFiles%\AutoHotkey\Lib or %A_MyDocuments%\AutoHotkey\Lib) and create a new cron timer:

; cron_insert(minutes, hours, days, months, daysofweek, target [, workingdir])
cron_insert("0,15,30,45","*","*","*","*","notepad.exe")      
;    Each entry can be a commaseparated list of values or * for all
;    The example above imply that notepad.exe is being started each 15 minutes, 
;    every hour, every day and every month.
;    For the daysofweek parameter 0 is sunday, * isn't expanded to every weekday

Still need some polishing and testing ;-)

majkinetor
  • Moderators
  • 4512 posts
  • Last active: Jul 29 2016 12:40 AM
  • Joined: 24 May 2006
Hej, thx for this, I tried different "crones" but ahk crone would definitely be my choice. The latest dissapointment was NNCron

I noticed
cron_next       = 0
cron_nextid     = 
cron_records    =
cron_target     = 
cron_workingdir = 
cron_table      =

Can you tell me when is this executed, if I add include at the end ?
Posted Image

tonne
  • Members
  • 1654 posts
  • Last active: May 06 2014 06:22 PM
  • Joined: 06 Jun 2006
I don't think it matters (maybe a left-over from my initial script where the functions wasn't moved in to a library) and they could probably be commented out with no harm.
Sort of placeholder for the global variables used in the various functions.

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
Nice work, especially the concise and clear documentation!

I've added this to my growling list of candidates for the stdlib in case it gets missed by the volunteers who will work on the stdlib.

Thanks for sharing it.

tonne
  • Members
  • 1654 posts
  • Last active: May 06 2014 06:22 PM
  • Joined: 06 Jun 2006
The promised GUI interface are now ready for testing, see http://www.autohotke...pic.php?t=22825.

wheeledgoat
  • Guests
  • Last active:
  • Joined: --
Hey -

Thanks a ton for putting the cron.ahk together!! It's just what I needed (don't have access to task scheduler on the work PC). However, I cannot get the dayofweek to work. No matter what I put in that 5th field, it still runs regardless of what day it is.

Here's my line;
cron_insert("57","13","*","*","0","iexplore.exe http://kronosweb.luhs.org/wfc/logon")
I currently have it at 1:57 just for testing purposes. You see I have the dayofweek set to sunday, but here I am wednesday and the sucker still launches. I want to make it M-F ("1,2,3,4,5").

I tried using the GUI builder, and it confirmed that the appropriate entries are 0-6 (but that wound up throwing me into some kind of loop which made me have to reboot - it kept executing the command over and over and overloaded the computer to where I couldn't end the process or even get the Task Manager loaded to kill it).

I see in the notes;

For the daysofweek parameter 0 is sunday, * isn't expanded to every weekday

Does this mean the feature isn't fully functioning yet? What does that mean? I'm using ver 0.4.

Thanks!

wheeledgoat
  • Guests
  • Last active:
  • Joined: --
I must say - the traytip balloon is a very nice touch! I was very impressed when that little puppy popped up. Looks cool!

But, alas, I really don't need another distraction. I've disabled it by commenting out the second line here;
If cron_tooltip <> Running
;    TrayTip,Cron job started,%cron_tooltip%,10
  If cron_pid
    SetTimer,cron_StopTimer,5000
  cron_restart()
Return
Should I really be commenting out this whole section?

Also, where is the timer value for the traytip? Maybe I'd like it better if it went away in 1-2 seconds... I tried messing with the "10" at the end of line 2, and also the 5000 in line 4, but no beans.

Thanks again for this awesome cron thing!

tonne
  • Members
  • 1654 posts
  • Last active: May 06 2014 06:22 PM
  • Joined: 06 Jun 2006
Thank you for the feedback - I have uploaded a new version with a fix in the expand function (used internally to expand say day 1-5 to 1,2,3,4,5).

Quote:
Also, where is the timer value for the traytip? Maybe I'd like it better if it went away in 1-2 seconds... I tried messing with the "10" at the end of line 2, and also the 5000 in line 4, but no beans.

The 10 are only an approximation as explained in the help file. It could be replaced by a timer as (not tested):
TrayTip,Cron job started,%cron_tooltip%,2 ; the timer doesn't matter
SetTimer,cron_HideTrayTip,-2000
...
cron_HideTrayTip:
TrayTip
Return

The cron_StopTimer is executed each 5 seconds and keeps an eye on the started processes to show a traytip with stopped jobs.
Never tested long running jobs and starting other jobs before the first finish...

wheeledgoat
  • Guests
  • Last active:
  • Joined: --
sorry if this is really dumb, but where is the updated file you speak of? the link at the top of this thread still links to ver 0.1 - I found ver 0.4 somewhere but I can't find it again.... did you rename the update to ver 0.41 or something?

thanks again! can't wait to try it out. (also, you understood that my problem wasn't with getting it to understand ranges (1-5 = 1,2,3,4,5) but that the dayofweek field didn't seem to work at all, right?)

tonne
  • Members
  • 1654 posts
  • Last active: May 06 2014 06:22 PM
  • Joined: 06 Jun 2006
My error - I uploaded to the wrong folder.

The link in the main post is valid.

wheeledgoat
  • Guests
  • Last active:
  • Joined: --
I'm so sorry for not getting this. Blame it on my being a spoiled american. Here's why I'm confused;

I think the file I'm using now is version 0.4 because it starts off like this:

; Version 0.4
; Added label as action
;
; Version 0.3
; Added parsing of ranges in cron 0-4=>0,1,2,3,4
; Added parsing of dividers i ncron 0-4/2=>0,2,4
;
; Version 0.2
; Prerequisites v1.0.47+
;
; Usage
; 1. place cron.ahk in standard or user library


...I can't remember or find where I got that from.

I'm clicking on the link at the top of this thread (where it says This library makes it possible to start multiple cron based timers in your script: Download cron library. ) It looks like it's linking to https://ahknet.autohotkey.com/~tonne/cron/Cron.ahk
It looks like it's still ver 0.1 because it starts off like this:

;------------------------
; @@@@ @@@@ @@@ @ @ ;
;@ @ @ @ @ @@ @ ;
;@ @@@@ @ @ @ @ @ ;
;@ @ @ @ @ @ @@ ;
; @@@@ @ @ @@@ @ @ ;
;------------------------
; Version 0.1 Beta
; Prerequisites v1.0.47+
;
; Usage
; 1. place cron.ahk in standard or user library

(of course all the @ symbols spell CRON)
I'm sure I'm going to feel like a real moron once it's explained to me, but as it stands now I'm bewildered.

...and again, thanks for your help - and also thanks again for writing this to begin with!!

tonne
  • Members
  • 1654 posts
  • Last active: May 06 2014 06:22 PM
  • Joined: 06 Jun 2006
The old version (0.1) is no longer on autohotkey.net - try restarting your browser or clear the cache.

wheeledgoat
  • Guests
  • Last active:
  • Joined: --
Nice tip on clearing the cache. I've heard of that being useful sometimes, but I've never actually had to do that before. Worked like a charm! (I told ya I'd feel like a fool!)

Unfortunately, the dayofweek still doesn't work. Here's my line of code, it still launches today when the time comes around even though I have the value set to "1" which should be Monday, right?
cron_insert("52","8","*","*","1","iexplore.exe http://kronosweb.luhs.org/wfc/logon")
(I'm using IE specifically because that app won't work with my default Firefox).


Also, what about this?
; this will make a list of valid values from min to max in step
cron_expand(min,max,step,byref result)
{
  msgbox % min " - " max ", " step 
  val = %min%
  Loop 
  {
    result .= (result <> "" ? "," : "") . val
    val += step
    If (val > max)
      Break
  }
As soon as you load your script that references the cron library, a bunch of msgboxes pop up. I tried running the script by clicking "OK" on all the boxes that pop up (about 20-30?), and then I also tried running the script by commenting out the "msgbox % min " - " max ", " step" line, didn't seem to make any difference so far as the functioning of the script.

tonne
  • Members
  • 1654 posts
  • Last active: May 06 2014 06:22 PM
  • Joined: 06 Jun 2006
You are right! I have fixed it and uploaded a version 0.5.1 (in the right location).

This seemed right when I wrote it:
; check if day is allowed or weekday is allowed
      ok = 0
      if day in %days%
        ok = 1
      if wday in %dayofweek%
        ok = 1
But the logic didn't hold. The fixed version is:
; check if day is allowed or weekday is allowed
      ok = 1
      if day not in %days%
        ok = 0
      if wday not in %dayofweek%
        ok = 0

Thanks again for reporting.

nnesori
  • Members
  • 16 posts
  • Last active: Jul 23 2009 05:03 PM
  • Joined: 14 Oct 2006
Great!! tonne. :D
Thanks for the sharing.

But, your code has a tiny problem.

e.g (A certain script not use "return"command )

;--cronTest.ahk
#persistent
cron_insert("30","*","*","*","*","notepad.exe")



When I run the cronTest.ahk,
The notepad be launched unconditionally at first.
So, I suggest that "return" add at top of the Cron.ahk (Auto-execute Section)
.