[Gambas-user] Best method to trigger event at midnight?

Randall Morgan rmorgan62 at ...626...
Sat Mar 23 20:32:30 CET 2013


Does it have to be from the running program? or can you use cron to
trigger an applet to accomplish what you need to? I do a lot of db
work and often need to run processes when the load is lite and
everyone is home in bed. I usually write these tasks as separate
applets and then let cron run them.

If I had to do it in my app, I would create a flag to indicate the
process was running and then check for a time span, say from 12:00AM -
12:15AM if i were worried about it being missed. Then when the process
was started I would set the flag to indicate that the process was
running. Then I'd reset the running flag at some point after the time
window to ensure the process wasn't ran more than once during the
window. Or if the process was expected to take many times long than
the start window, I would simply let the process reset the flag on
exit.

Hope that gives you some ideas....




On Sat, Mar 23, 2013 at 12:20 PM, Tobias Boege <taboege at ...626...> wrote:
> On Sat, 23 Mar 2013, Beno?t Minisini wrote:
>> Le 23/03/2013 19:43, dr.diesel a ?crit :
>> > I'm looking to trigger an event at midnight, any suggestions on the best
>> > method to ensure the time is not missed?
>> >
>> > My application reads/writes a DB, launches websites and reads heavily on the
>> > COM port.  I'm afraid that if I simply look for the date/time to be 00:00
>> > I'll miss the time while some other event is happening.  Do I need to just
>> > carefully code this or is there some other method I'm not seeing?
>> >
>> > Many thanks
>> > Andy
>> >
>>
>> Check the time with two timers.
>>
>> For example, the first timer will be raised for example each hour. And
>> when it is past 23:00, start another timer with a more precise
>> resolution to check when midnight is reached.
>>
>> You can use more timers. It depends on which precision you need.
>>
>> But beware that there is only one thread in Gambas, so a too long event
>> handler prevents other events to be raised.
>>
>> Regards,
>
> Isn't it simpler to calculate the time delta until midnight and then,
> depending on what the application otherwise does:
>
> a) it's otherwise idle: Wait iDelay (or even Sleep iDelay)
> b) it has something to do: arm a Timer with iDelay to expire once
>
> This would require only one Timer and less overall effort. Any
> inconvenience I missed with this approach?
>
> Regards,
> Tobi
>
> ------------------------------------------------------------------------------
> Everyone hates slow websites. So do we.
> Make your web apps faster with AppDynamics
> Download AppDynamics Lite for free today:
> http://p.sf.net/sfu/appdyn_d2d_mar
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user



-- 
If you ask me if it can be done. The answer is YES, it can always be
done. The correct questions however are... What will it cost, and how
long will it take?




More information about the User mailing list