Jump to content
Sign in to follow this  
Andrew Sparkes

A scheduled event program

Recommended Posts

Andrew Sparkes

OK, here is the problem.

I want a program to read an time interval from an ini, do function x at the time interval read from the ini, and stay running 24/7. I tried it before and failed... My problem with the original code was that I wanted to check the time every 5 mins or so to stop the cpu lagging and instead of doing the event once, it ran every five minutes when the time was correct. Anyone have a bare bones scheduler script?


---Sparkes.

Share this post


Link to post
Share on other sites
/dev/null

OK, here is the problem.

I want a program to read an time interval from an ini, do function x at the time interval read from the ini, and stay running 24/7. I tried it before and failed... My problem with the original code was that I wanted to check the time every 5 mins or so to stop the cpu lagging and instead of doing the event once, it ran every five minutes when the time was correct. Anyone have a bare bones scheduler script?

Here we go. Maybe you'll have to adjust time/date handling a bit, but I think it's a good start.

#Include <Date.au3>
const $INTERVAL = 5 * 5; Interval in seconds.
global $ACTIONTIME = "2005/10/22 22:33:42"
    
$timer = TimerInit()

while 1
    sleep(1000)

    $diff = TimerDiff($timer) / 1000
    if $diff > $INTERVAL then
        $timer = TimerInit()
        _continuous_worker_task()
    endif
    
    if _DateDiff("s",$ACTIONTIME,_NowCalc()) >= 0 then
        $ACTIONTIME = _DateAdd ( "d", 1, $ACTIONTIME )
        _single_action_task()
    endif 
wend

func _continuous_worker_task()
    msgbox(0,"","delta time: " & $INTERVAL & " seconds have elapsed...")
endfunc

func _single_action_task()
    msgbox(0,"","SINGLE ACTION TASK !!!! ...")
endfunc

Cheers

Kurt

Edited by /dev/null

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites
Andrew Sparkes

That code looks like it'll work for my project, but would you mind explaining the date and timer specific functions ? I don't understand the usage of the commands dealing with the time. Care to enlighten me?


---Sparkes.

Share this post


Link to post
Share on other sites
/dev/null

That code looks like it'll work for my project, but would you mind explaining the date and timer specific functions ? I don't understand the usage of the commands dealing with the time. Care to enlighten me?

please read the help file. It's all explained there.

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites
Andrew Sparkes

I have already looked through the help files and know what the Timer funcs do, but when combined with the date add and diff funcs, I'm lost. From what I determine, I see that it is a loop that has a one second delay and does a few things:

-assigned the quotient of Timerdiff($timer) and 1000 to $diff

-checks if $diff is greater than $INTERVAL and if it is, Resets the timer and runs continuous worker task

-checks if _nowcalc() - $ACTIONTIME is >= 0 and if it is, assign $actiontime + 1 day to $actiontime, and then run the single action task.

My questions lie mostly in the second if statement. What is the purpose of the Dateadd and DateDiff funcs? If i read that right, $ACTIONTIME is the time of execution for single action task. What modifications do i need to do if there is multiple run times every 24 hour period?

Here is an example of what I want to do:

The program read an ini for $email, $password and $number

If $number is 2 run func x every 12 hours, if 3, run func x every 8 hours and so on. interval = 24/$number

func x is already defined and all that is needed is a reliable schedule program structure.

Thanks. I appreciate the help.

Edited by Andrew Sparkes

---Sparkes.

Share this post


Link to post
Share on other sites
/dev/null

My questions lie mostly in the second if statement. What is the purpose of the Dateadd and DateDiff funcs? If i read that right, $ACTIONTIME is the time of execution for single action task. What modifications do i need to do if there is multiple run times every 24 hour period?

based on what you say below, you don't need _DateAdd() and _DateDiff().

Here is an example of what I want to do:

The program read an ini for $email, $password and $number

If $number is 2 run func x every 12 hours, if 3, run func x every 8 hours and so on. interval = 24/$number

func x is already defined and all that is needed is a reliable schedule program structure.

What you need is only the first part, where the script tests if a given amount of time has passed by (first if clause within the while loop). Could you please post what you have tried so far? I will have a look at your code. func x would be interesting as well....

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×