loop_dance - background deployment planner
Recently, projects often have to create a daemon that periodically checks or sends out something in the background.
Typically, a similar task is solved using packages such as whevenever, daemon_controller, daemon_generator, etc. and everything seemed to be simple and clear, but every time tired of framing the garden and writing the same thing. I just need to run some User.notify_all once an hour.
Presenting loop_dance - a gem for quickly deploying a managed daemon in a rail environment.
We insert the package into our Gemfile, then remember to update bundle
Create a file lib / loop_dance.rb with tasks and the specified frequency.
For example: Notify all users every 3 hours. Check reports every 60 seconds.
That's all.
We created the first dancer, which will start automatically at the next restart of the rail server, will hang in the system as an independent daemon and perform tasks with the specified frequency.
You can also manage it manually:
And you can from the application itself:
Project address: github.com/dapi/loop_dance
Related links:
ruby-toolbox.com/categories/daemon_management.html
ruby-toolbox.com/categories/daemonizing.html
ruby-toolbox.com/categories/scheduling.html
Typically, a similar task is solved using packages such as whevenever, daemon_controller, daemon_generator, etc. and everything seemed to be simple and clear, but every time tired of framing the garden and writing the same thing. I just need to run some User.notify_all once an hour.
Presenting loop_dance - a gem for quickly deploying a managed daemon in a rail environment.
Conditions
- Minimum redundant code. Only what needs to be started and with what frequency.
- The code is executed in a rail environment.
- The daemon should automatically start / restart when the project is deployed.
- The ability to control the daemon through rake-tasks or directly from the application (it's nice to see its status on the admin panel)
We dance
We insert the package into our Gemfile, then remember to update bundle
gem "loop_dance"
Create a file lib / loop_dance.rb with tasks and the specified frequency.
For example: Notify all users every 3 hours. Check reports every 60 seconds.
class Dancer1 < LoopDance::Dancer
every 3.hours do
User.notify_all
end
every 60.seconds do
Report.checks
end
end
That's all.
We created the first dancer, which will start automatically at the next restart of the rail server, will hang in the system as an independent daemon and perform tasks with the specified frequency.
You can also manage it manually:
rake loop_dance:start_all
rake loop_dance:stop_all
rake loop_dance:status
rake loop_dance:dancer1:start
rake loop_dance:dancer1:stop
rake loop_dance:dancer1:status
And you can from the application itself:
Dancer1.start unless Dancer1.running?
Project address: github.com/dapi/loop_dance
Related links:
ruby-toolbox.com/categories/daemon_management.html
ruby-toolbox.com/categories/daemonizing.html
ruby-toolbox.com/categories/scheduling.html