Question

I recently added a delayed_job rap to my after_restart phase. Like so :

system "script/delayed_job stop"
system "script/delayed_job start -n 3"

Which works for the most part. Until I ran into a little snag today. I found an instance of delayed_job still running even after I repeatedly and manually did script/delayed_job stop.

I still get this :

user@ip-10-126-6-125 /data/HQ_Channel2/current $ ps aux | grep del
user   11034  0.0  3.4  74016 61964 ?        S    Dec05   0:19 delayed_job.0                     
user   11036  0.0  3.5  73660 63516 ?        S    Dec05   0:21 delayed_job.1                     
user   11038  0.0  3.6  73980 65256 ?        S    Dec05   0:17 delayed_job.2

Is it improper of me to be trying to close this via script/delayed_job stop ?

The only other way I know how to kill this is with a kill -9 , but isn't this overkill? And what's more, how would I implement that dynamically?

Was it helpful?

Solution

I've had a similar problem.

Check out Engine Yard's delayed_job recipe, specifically its template with start and stop commands. It uses a script at /engineyard/bin/dj on your Engine Yard instance.

<% (@num_workers || 1).times do |num| %>
  check process <%= @worker_name %>_<%= num %>
    with pidfile /var/run/engineyard/dj/<%= @app_name %>/dj_<%= @worker_name %>.pid
    start program = "/engineyard/bin/dj <%= @app_name %> start <%= @framework_env %> <%= @worker_name %>" with timeout 60 seconds
    stop program = "/engineyard/bin/dj <%= @app_name %> stop <%= @framework_env %> <%= @worker_name %>" with timeout 60 seconds
    if totalmem is greater than 300 MB then restart # eating up memory?
    group dj_<%= @app_name %>
<% end %>

When the stop script is called, it first uses kill -15 (TERM), waits for a grace period that defaults to 60 seconds, and if it's still alive, then uses kill -9.

Use Engine Yard's script (and recipe, for that matter) if you can to reduce maintenance later. But if it doesn't work for you, you can base your script off of these concepts. I've had some issues with it upgrading to Rails 3 so it may or may not work for you. I just contacted Engine Yard about it, but I doubt this is a high priority for them. Maybe if you contact them also, that will change.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top