Is it possible to do the following using delayed_job:
Define a class called Tasks
Have a method in Tasks run after every 5 minutes: Tasks.do_processing
When the next 5 minute cycle comes around, then run Tasks.do_processing
only if the previous do_processing
has completed
Is this something I have to create on my own or can delayed_job (or some other gem/plugin) do this?
Ps. I know about OS-level cron jobs, but if I used that then it would mean that each time the cron "fired" it would re-load the entire Rails environment, whereas delayed_job only needs to load it once.
If you'd like to do something similar to this :
class MyJob
run_every 1.day
def perform
# code to run ...
end
end
then try out this code: https://gist.github.com/1024726
You may consider creating a Rake task or other similar standalone processes that takes care of this functionality, and then wrapping it up with Daemons:
What is Daemons?
Daemons provides an easy way to wrap existing ruby scripts (for example a self-written server) to be run as a daemon and to be controlled by simple start/stop/restart commands.
If you want, you can also use daemons to run blocks of ruby code in a daemon process and to control these processes from the main application.
Besides this basic functionality, daemons offers many advanced features like exception backtracing and logging (in case your ruby script crashes) and monitoring and automatic restarting of your processes if they crash.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With