Search code examples
ruby-on-railsamazon-web-servicesamazon-ec2resquejob-scheduling

How to run a long running job on Amazon EC2 instance in Rails?


I'm using resque gem, and I'm running the jobs through the following command:

rake resque:work QUEUE='*'

But the problem is: As my SSH connection with remote server gets disconnected, or I close the SSH session window that is running the process rake resque:work QUEUE='*', it stops running the job.

I'd like to have a way in which the job will run independently: no need to remain connected with through SSH. Is there a way, or should I follow this procedure to accomplish what I require?


Solution

  • For this you can run rake task in background. There are multiple ways to accomplish this. Two of them are here:

    1. Using daemon you can run a rake task in background. Here is link for what is daemon. Here is link, How to achieve this for rails rake tasks. Appending & to rake task is my preferred way.

    2. Implement a cron to run rake task individually.