0

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?

Arslan Ali
  • 17,418
  • 8
  • 58
  • 76

2 Answers2

3

One more way to run task in background: screen. It creates as many shell sessions as you need, and they can be detached from your initial session. Run:

screen (you'll be in a new shell session)

/path/to/your/script > /path/to/log_file

Ctrl+A, Ctrl+D (here you return to the initial shell session, whilst the session you started your script will continue to run)

You can watch progress by tail -f /path/to/log_file, log off and log on again. To return to the detached session run screen -r.

If you don't have screen installed run yum install screen. Unsure about Ubuntu, perhaps it'll be apt-get install screen. Run man screen for more details.

Putnik
  • 5,925
  • 7
  • 38
  • 58
1

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.

Community
  • 1
  • 1
Dipak Gupta
  • 7,321
  • 1
  • 20
  • 32
  • Sorry I'm new to this thing: do I need to have *whenever* gem to run a cron easily? – Arslan Ali Jun 25 '16 at 10:06
  • Yes you need whenever to setup cron on server. didn't you try `rake resque:work QUEUE='*' &`. This is what you should run. – Dipak Gupta Jun 26 '16 at 16:27
  • For proper solution you should read this http://stackoverflow.com/questions/26260733/how-to-daemonize-rails-rake-task-on-elastic-beanstalk-start-up . – Dipak Gupta Jun 26 '16 at 16:32