Re: Background daemon

Michael Guterl
Mon, 03 Aug 2009 02:47:13 -0000

Penelope West wrote:
> It''s sending e-mail every hour, but I changed to sleep for a day,
but
> keep send the e-mail by hour. I don''t know what to do to send
daily.
> Could somebody help me?
>
>
> thanks
> ############
> #  mailer.rb
> ###############
> #!/usr/bin/env ruby
>
>
> # You might want to change this
> ENV["RAILS_ENV"] ||= "production"
>
> require File.dirname(__FILE__) + "/../../config/environment"
>
> $running = true
> Signal.trap("TERM") do
>   $running = false
> end
>
> while($running) do
>
>     Notifier.deliver_report_daily
>     #ActiveRecord::Base.logger.info "This daemon is still running at
> #{Time.now}.\n"
>
>     sleep 86400
>
> end
>
> ###########
> # deploy.rb
> ############
> desc "Stop daemons before deploying"
> task :before_deploy do
> run "#{current_path}/script/daemons stop"
> end
>
> desc "Start daemons after deploying"
> task :after_deploy do
> run "#{current_path}/script/daemons start"
> end

I certainly would not use a long running daemon for this purpose.  You
should look into using cron and script/runner to execute the task daily.

0 8 * * * /path/to/rails/app/script/runner -e production
"Notifier.deliver_report_daily"

This will deliver your daily report each day at 8 am.

Best,
Michael Guterl
--
Posted via http://www.ruby-forum.com/.