Am using gem clockwork for running scheduled jobs. I need to access all events defined in clock.rb for manually trigger the clockwork events when it fails.
For that I forked the clockwork gem by adding attr_reader: events
in clockwork/manager.rb
file.
clock.rb
module Clockwork
every(10.seconds, 'job1') do
p Clockwork.manager.events
end
end
By using Clockwork.manager.events
in clock.rb it returns all events that defined in clock.rb.
mycontroller.rb
module Admin
class MyController < AdminController
require 'clockwork'
def index
@events = Clockwork.manager.events
end
end
end
But while using it in controller it returns empty value.
How to get all clockwork events in controller?
In development
mode not all application code is loaded during startup, likely the code where you defined your events is not loaded yet.
You can require
that specific file in your controller, afterwards they should be visible.
In production
mode all code is loaded during startup so in that mode it should already work.