+1 for EM + bluepill

+++ lib/trend_muncher.rb +++

EventMachine::PeriodicTimer.new(5) do
   queue = check_whether_there_is_something_new_in_the_queue
   while queue > 0
     logger.info "Munching #{queue.size} trends"
     Trends.create(:data => queue.data)
   end
end


+++ config/muncher.pill +++

RAILS_ROOT = File.expand_path("#{File.dirname(__FILE__)}/..") unless
defined?(RAILS_ROOT)

Bluepill.application("MuncherEnvironment") do |app|
  app.working_dir = RAILS_ROOT

  app.process("TrendMuncherDaemon") do |process|
    process.start_command = "ruby lib/trend_muncher.rb"
    process.stop_command = "kill -INT {{PID}}"
    process.pid_file = RAILS_ROOT + "/tmp/pids/trend_muncher.pid"
    process.stdout = RAILS_ROOT + "/log/muncher.log"
    process.daemonize = true

    process.checks :flapping, :times => 2, :within =>
30.seconds, :retry_in => 60.seconds
    process.checks :mem_usage, :every => 10.seconds, :below =>
150.megabytes, :times => [3,5]
  end
end

and then...

`sudo bluepill load config/muncher.pill`

Good luck!

On Oct 13, 10:42 am, Joshua Partogi <[email protected]> wrote:
> Hi all,
>
> I have another noobie question. After looking at last night
> presentation about Rails 3, I am wondering where do we put piece of
> code that runs on a separate thread for a long time every 5 seconds?
> e.g
>
> Thread.new do
>   while true
>     queue = check_whether_there_is_something_new_in_the_queue
>
>     while queue > 0
>       Trends.create(:data => queue.data)
>     end
>
>     sleep 5
>   end
> end
>
> 1. I don't really like using cron to call `script/rails runner` as
> that will load the whole rails library which will choke the server
> because this process is run every 5 seconds.
> 2. I don't know about resque (which was mentioned by Ryan) yet, but
> since resque is a separate webapp, would resque know anything about
> the models in my Rails app?
>
> Any input is highly appreciated.
>
> Kind regards,
> Josh
>
> --http://twitter.com/scrum8

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
or Rails Oceania" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rails-oceania?hl=en.

Reply via email to