Cron scheduling for daemon gem


#1

Does anyone know how to do cron-like scheduling with the daemon gem?
basically i need my script to execute every day at 4 a.m. Here’s what
the default files comes with

while($running) do

Replace this with your code

ActiveRecord::Base.logger.info “This daemon is still running at
#{Time.now}.\n”

sleep 10
end

I just need a way to substitute “sleep 10” with “runs every day at 4
a.m.” I really looked around but cant seem to find the answer. Btw i
tried backgroundrb but I was having problems with it so i’m trying to
just do it with daemons. Any help would be greatly appreciated.


#2

If you need to perform some action at particular time then you should
test is is a time to action.
If time is right, do you thing.
If not then sleep a while and then test it once again.

You can have an initial sleeping interval and then you can adjust in
correlation how far is the next running time.

What issues you have with backgroundrb (http://
backgroundrb.rubyforge.org/scheduling/)?


#3

Dejan D. wrote:

If you need to perform some action at particular time then you should
test is is a time to action.
If time is right, do you thing.
If not then sleep a while and then test it once again.

You can have an initial sleeping interval and then you can adjust in
correlation how far is the next running time.

What issues you have with backgroundrb (http://
backgroundrb.rubyforge.org/scheduling/)?

yeah I could do that but I was hoping to do something along the lines
cron syntax like 0 30 1 * * * *. That would be nice for what I’m trying
to do. Or something like :hour => 4. I just dont know the syntax to do
that with daemon. I guess if I had to, I could do what you suggest.

I wasn’t having problems with scheduling in backgroundrb, was just
having issues getting my functions to work. There were many problems but
the one I’m having now is I get

Invalid worker with name alerts_worker and key
/Library/Ruby/Gems/1.8/gems/packet-0.1.14/lib/packet/packet_connection.rb:52:in
`ask_worker’

Besides, backgroundrb probably isn’t necessary for the tasks i’m trying
to do. I just want to figure out how make scheduling in daemon.