Is better to fetch mail using 'cron' + 'fetchmail' or 'getmail'.  I think.
But, the question is worth the trouble (statusd_dgs.lua by Jeremy Hankins is a 
good example
on this). I will draw some answers, actually, I only tried the third answer:

Lets assume:  defaults = { update_interval = 4*1000, foo_interval = 2.5*60*1000 
}
              local settings = table.join( ... )


1-) A simple statement accumulating time running in some foo variable:

        local foo = settings.update_interval  --> foo is actually a global 
variable
        
        if [ foo >= foo_interval ] then
                 fetch_something()
                 foo = settings.update_interval  --> If its done, re-init foo
        else
                 foo = foo + settings.update_interval  --> Acummulate time 
running
        end

-- The bad thing about this is that the real foo_interval is not exactly 2.5 
minutes for some
-- possible cases. Also, an update_interval bigger than foo_interval will make 
useless the
-- foo_interval, but could work for some body. Lets Move on.


2-) A function to calculate internal times:

        local init_time = os.time()*1000   --> A fallacy to calculate 
update_interval milliseconds
        local new_update = settings.update_interval
-->     A declaration like this must be done at the top of the script.

        function check_foo()
                local time = os.time()*1000 - init_time
                if time == foo_interval then
                        fetch_something()
                        init_time = init_time + foo_interval
                        new_update = settings.update_interval --> Re-init 
normal update_interval
                        return
                elseif ( time + settings.update_interval > foo_interval ) and
                        ( foo_interval - time < settings.update_interval) then
                        new_update = foo_interval - time
                        return
                end
        end
        
        function update_foo()
                check_foo()
                show_foo()
                foo_timer:set(new_update, update_foo)  --> Internal 
'update_interval' is new_update
        end

-- 
Last.fm profile:
http://www.last.fm/user/nmental
Stick to Nmental.com soon
Release: first weekends of jan
http://www.nmental.com

Reply via email to