# Cron scheduling for daemon gem

**URL:** <https://www.ruby-forum.com/t/cron-scheduling-for-daemon-gem/156220>\
**Category:** Rails\
**Created:** [December 22, 2008, 11:00pm UTC](https://www.ruby-forum.com/t/cron-scheduling-for-daemon-gem/156220 "2008-12-22T23:00:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pimeamark](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9e8a1a/32.png) [@pimeamark](https://www.ruby-forum.com/u/pimeamark)\
**Post date:** [December 22, 2008, 11:00pm UTC](https://www.ruby-forum.com/t/cron-scheduling-for-daemon-gem/156220/1 "2008-12-22T23:00:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pimeamark](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9e8a1a/32.png) [@pimeamark](https://www.ruby-forum.com/u/pimeamark)\
**Post date:** [December 22, 2008, 11:45pm UTC](https://www.ruby-forum.com/t/cron-scheduling-for-daemon-gem/156220/2 "2008-12-22T23:45:57Z")

</div>

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/](http://backgroundrb.rubyforge.org/scheduling/))?

---

<div class="post-metadata">

**Author:** ![pimeamark](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9e8a1a/32.png) [@pimeamark](https://www.ruby-forum.com/u/pimeamark)\
**Post date:** [December 23, 2008, 12:23am UTC](https://www.ruby-forum.com/t/cron-scheduling-for-daemon-gem/156220/3 "2008-12-23T00:23:52Z")

</div>

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/](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.
