Can I start and stop slow-motion workers from my Rails application?

I have an application that can benefit from delayed_job and some background processing. The thing is, I really don't need / need delayed_job workers to work all the time.

The application works in a shared hosting environment and in different places (for different users). In addition, the application does not receive a large amount of use.

Is there a way to start and stop processing tasks (either using a script task or a rake) from my application only after certain actions / events?

+3
source share
4 answers

You can call the system:

system "cd #{Rails.root} && rake delayed_job:start RAILS_ENV=production"

delayed_job, . 5- 15 - .

+4

, , , . , , - ? ? ?

delayed_job , .

Delayed::Worker::sleep_delay = 60 * 5  # in your initializer.rb

db 5 . "" .

Delayed::Worker, work_off script/run_jobs_and_exit script. , script/delayed_job does - 3 .

0

, , , , . - Google :

http://viatropos.com/blog/how-to-run-background-jobs-on-heroku-for-free/

. :

" , .., . , - . , Heroku API, 1. , , , - . , 0. , . , , 1 . , $0,05 .:)"

0

If you go to stop the employee, you are given a PID. You can just kill -9 PID if all else fails.

0
source

Source: https://habr.com/ru/post/1722731/


All Articles