[英]access all events from clockwork manager to controller
Am using gem clockwork for running scheduled jobs. 我正在使用gem发条来运行计划的作业。 I need to access all events defined in clock.rb for manually trigger the clockwork events when it fails.
我需要访问在clock.rb中定义的所有事件,以便在失败时手动触发发条事件。
For that I forked the clockwork gem by adding attr_reader: events
in clockwork/manager.rb
file. 为此,我通过在
clockwork/manager.rb
文件中添加attr_reader: events
来创建clockwork/manager.rb
。
clock.rb 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. 通过在clock.rb中使用
Clockwork.manager.events
,它返回在clock.rb中定义的所有事件。
mycontroller.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. 在
development
模式下,并非在启动过程中加载了所有应用程序代码,可能是您定义事件的代码尚未加载。
You can require
that specific file in your controller, afterwards they should be visible. 您可以在控制器中
require
该特定文件,之后它们应该是可见的。
In production
mode all code is loaded during startup so in that mode it should already work. 在
production
模式下,所有代码都在启动期间加载,因此在该模式下它应该已经可以工作了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.