Showing posts with label delayed-job. Show all posts
Showing posts with label delayed-job. Show all posts

Tuesday, March 1, 2011

Monitor Delayed Job in rails

by sandipransing 0 comments
Delayed Job & Monit configuration
We were struggling through how to monit delayed_job from past few months because monit doesn't work seamlessly with delayed_job start/stop commands and finally we got able to monit delayed_job.
Here is our old configuration that wasn't working anyhow-
check process delayed_job with pidfile /home/sandip/shared/pids/delayed_job.pid stop program = "/bin/bash -c 'cd /home/sandip/current && RAILS_ENV=production script/delayed_job stop'" start program = "/bin/bash -c 'cd /home/sandip/current && RAILS_ENV=production script/delayed_job start'" if totalmem > 100.0 MB for 3 cycles then restart if cpu usage > 95% for 3 cycles then restart
After doing google & looking at stackoverflow, we found different solutions to work with but none of them found useful to me. :(
After reading google group someone (not remembering exactly) directed to write a init script for delayed_job server and that perfectly worked for me and my headache of self moniting delayed_job ended up ;)
Here is delayed_job init script
## /etc/init.d/delayed_job
#! /bin/sh set_path="cd /home/sandip/current" case "$1" in start) echo -n "Starting delayed_job: " su - root -c "$set_path; RAILS_ENV=production script/delayed_job start" >> /var/log/delayed_job.log 2>&1 echo "done." ;; stop) echo -n "Stopping delayed_job: " su - root -c "$set_path; RAILS_ENV=production script/delayed_job stop" >> /var/log/delayed_job.log 2>&1 echo "done." ;; *) echo "Usage: $N {start|stop}" >&2 exit 1 ;; esac exit 0 finally here is the working monit delayed_job configuration
check process delayed_job with pidfile /home/sandip/shared/pids/delayed_job.pid stop program = "/etc/init.d/delayed_job stop" start program = "/etc/init.d/delayed_job start" if totalmem > 100.0 MB for 3 cycles then restart if cpu usage > 95% for 3 cycles then restart Thinking Sphinx monit configuration
check process sphinx with pidfile /home/sandip/shared/pids/searchd.pid stop program = "/bin/bash -c 'cd /home/sandip/current && /usr/bin/rake RAILS_ENV=production ts:stop'" start program = "/bin/bash -c 'cd /home/sandip/current && /usr/bin/rake RAILS_ENV=production ts:start'" if totalmem > 85.0 MB for 3 cycles then restart if cpu usage > 95% for 3 cycles then restart Adhearsion (ahn) monit confiuration
check process ahn with pidfile /home/josh/shared/pids/ahnctl.pid stop program = "/bin/bash -c 'cd /home/sandip/current && /usr/bin/ahnctl stop adhearsion'" start program = "/bin/bash -c 'cd /home/sandip/current && /usr/bin/ahnctl start adhearsion'" if totalmem > 100.0 MB for 3 cycles then restart if cpu usage > 95% for 3 cycles then restart Nginx monit configuration
check process nginx with pidfile /opt/nginx/logs/nginx.pid start program = "/opt/nginx/sbin/nginx" stop program = "/opt/nginx/sbin/nginx -s stop" if cpu is greater than 70% for 3 cycles then alert if cpu > 80% for 5 cycles then restart if 10 restarts within 10 cycles then timeout
Read More…

Wednesday, October 6, 2010

DelayedJOb's (DJ) fancy methods

by sandipransing 0 comments
Delayed Job provides send_later and send_at as instance as well as class_methods methods along-with handle_asynchronously as class method to be written inside class

module Delayed module MessageSending def send_later(method, *args) Delayed::Job.enqueue Delayed::PerformableMethod.new(self, method.to_sy m, args) end def send_at(time, method, *args) Delayed::Job.enqueue(Delayed::PerformableMethod.new(self, method.to_sy m, args), 0, time) end module ClassMethods def handle_asynchronously(method) aliased_method, punctuation = method.to_s.sub(/([?!=])$/, ''), $1 with_method, without_method = "#{aliased_method}_with_send_later#{pu nctuation}", "#{aliased_method}_without_send_later#{punctuation}" define_method(with_method) do |*args| send_later(without_method, *args) end alias_method_chain method, :send_later end end end end
Usage of send_later, send_at and handle_asynchronously
# instance method user.send_later(:deliver_welcome) # class_method Notifier.send_later(:deliver_welcome, user) Notifier.send_at(15.minutes.from_now, :deliver_welcome, user) # Inside User class write below line after deliver_welcome method handle_asynchronously :deliver_welcome
Read More…

Tuesday, October 5, 2010

Solution to DelayedJob(DJ) gem server start problem

by sandipransing 0 comments
Solution to DelayedJob(DJ) gem server start problem
I had installed delayed_job gem 2.0.3, daemons gem but after staring DJ server it shows daemon started but actually process gets killed automatically.
I performed steps given by Kevin on google group and it worked like charm
Here are the steps:

1) sudo gem sources -a http://gems.github.com
2) sudo gem install alexvollmer-daemon-spawn
3) Move the old daemons delayed job script out of the way -> mv script/delayed_job script/delayed_job.daemons
4) Make this your new script/delayed_job: http://gist.github.com/104314

Try it out again making sure it writes to the tmp/pids directory ok.
My line looks like this:
RAILS_ENV=production script/delayed_job start
then to check (besides running 'ps'), you can run this:
RAILS_ENV=production script/delayed_job status
Read More…

Wednesday, January 13, 2010

Delayed Job changing job parameters in Rails

by sandipransing 0 comments
Delayed job variables initialization written on at collectiveidea / delayed_job doesn't work.
# config/initializers/delayed_job_config.rb Delayed::Worker.destroy_failed_jobs = false Delayed::Worker.sleep_delay = 60 Delayed::Worker.max_attempts = 3 Delayed::Worker.max_run_time = 5.minutes
Here is the correct way of doing it as mentioned on tobi / delayed_job
# config/initializers/delayed_job_config.rb Delayed::Job.destroy_failed_jobs = false silence_warnings do Delayed::Job.const_set("MAX_ATTEMPTS", 3) Delayed::Job.const_set("MAX_RUN_TIME", 5.minutes) end
Read More…

About The Author

Sandip is a ruby on rails developer based in pune and also a blogger at funonrails. Opensource contributor and working with Josh software Private Limited. for more info read Follow Sandip on Twitter for updates.

Connect With Me...

Github Projects

@sandipransing Twitter