Jinah Adam
Jinah Adam

Reputation: 1125

Rake Task Starts But Stops abruptly when executed via controller

I have a set of rake tasks that run on the production server, its detached from the main thread, and happens in the background

here is the code to execute it

def vehicle
    @estate = Estate.find(@estate_id)
    @date_string = @login_month.strftime("%m%Y")
    system("rake udpms:process_only_vehicle[#{@date_string},#{@estate_id}] &")
    redirect_to :controller => "reports/error_messages", :message => "Processing will happen in the background and reports will be refreshed after two minutes", :target => "_blank"
  end

when this code is executed via the url route, it runs the rake task, i can see if i check the active processes on the production machine, but it ends abruptly after about 10 seconds.

ps axl | grep rake

this is the it shows

ruby /usr/local/rvm/gems/ruby-1.8.7-p352/bin/rake udpms:process_only_vehicle[082012,5]

if i execute the same same rake task in the app folder in the terminal it runs with out any errors. This runs without any issues on the dev machine. (OSX). Server is Mint. Rake version is the same on both. there is only one version of the gem.

since its the production server there are no logs (other than the produciton.log, and its no help). any help on how i go about debugging this issue will be much appreciated.

Upvotes: 1

Views: 299

Answers (1)

Veraticus
Veraticus

Reputation: 16074

This is probably happening because your server software reaps requests that take longer than 10 seconds to respond. Despite the fact you're kicking off a rake task, it still has to wait for that system call to execute: if it takes awhile then the task will be terminated and the server worker returned to the worker pool.

In a more general sense, this is not the appropriate way to make a task happen in the background. You probably want to use Resque or Delayed Job, which enqueue tasks and run them in the background for you.

Upvotes: 1

Related Questions