What's the best way to run scheduled tasks in a Rails environment? Script/runner? Rake?
相关问题
- Question marks after images and js/css files in ra
- Using :remote => true with hover event
- Eager-loading association count with Arel (Rails 3
- Is there a way to remove IDV Tags from an AIFF fil
- Rails how to handle error and exceptions in model
相关文章
- Right way to deploy Rails + Puma + Postgres app to
- AWS S3 in rails - how to set the s3_signature_vers
- how to call a active record named scope with a str
- How to add a JSON column in MySQL with Rails 5 Mig
- “No explicit conversion of Symbol into String” for
- form_for wrong number of arguments in rails 4
- Rspec controller error expecting <“index”> but
- Factory_girl has_one relation with validates_prese
you can use resque and resque-shheduler gem for creating crons, this is very easy to do.
https://github.com/resque/resque
https://github.com/resque/resque-scheduler
I'm using the rake approach (as supported by heroku)
With a file called lib/tasks/cron.rake ..
To execute from the command line, this is just "rake cron". This command can then be put on the operating system cron/task scheduler as desired.
Update this is quite an old question and answer! Some new info:
I'm a big fan of resque/resque scheduler. You can not only run repeating cron-like tasks but also tasks at specific times. The downside is, it requires a Redis server.
Once I had to make the same decision and I'm really happy with that decision today. Use resque scheduler because not only a seperate redis will take out the load from your db, you will also have access to many plugins like resque-web which provides a great user interface. As your system develops you will have more and more tasks to schedule so you will be able to control them from a single place.
Using something Sidekiq or Resque is a far more robust solution. They both support retrying jobs, exclusivity with a REDIS lock, monitoring, and scheduling.
Keep in mind that Resque is a dead project (not actively maintained), so Sidekiq is a way better alternative. It also is more performant: Sidekiq runs several workers on a single, multithread process while Resque runs each worker in a separate process.
Probably the best way to do it is using rake to write the tasks you need and the just execute it via command line.
You can see a very helpful video at railscasts
Also take a look at this other resources: