Setup
ChronoTrigger is designed to work with Rails 5.2 and beyond. It has minimal gem dependencies and no infrastructure dependencies.
In the app/events
folder, we will create an ApplicationEvent
class for our Event
classes to inherit from:
While you can use ChronoTrigger to run any code, it has been designed to work with CableReady. Including CableReady::Broadcaster
makes the cable_ready
method available to all of your Event
classes.
If you plan to use CableReady to send rendered HTML, you might wish to delegate render
to ApplicationController
.
Finally, you need to start the Clock
! The best place to do this is after Puma starts up:
Optional: Create an initializer
Today, it's possible to configure the resolution of the timer, but the 100ms default is likely fine. There will be additional options added in the future:
You might be wondering: why not start the Clock
in the initializer? The reason is that you only want to run ChronoTrigger in the web server process - not Sidekiq, console, when running migrations and other rake tasks...
Last updated