简体   繁体   English

Rails Clockwork 事件在本地被调用两次

[英]Rails Clockwork events getting called twice locally

When I run my clockwork file, events are registered twice.当我运行我的发条文件时,事件被注册两次。 Am I doing something wrong?难道我做错了什么?

CLI I'm running locally to test: clockwork app/lib/clockwork/clock.rb CLI 我在本地运行进行测试: clockwork app/lib/clockwork/clock.rb

clock.rb:时钟.rb:

require 'clockwork'
require 'active_support/time'
require './config/boot'
require './config/environment'

module Clockwork
  handler do |job, time|
    puts "Running #{job} at #{time}"
    puts
  end

  every(1.hour, 'test') do 
    puts 'RUNNING TEST'
  end
end

The output:输出:

I, INFO -- : Starting clock for 2 events: [ test test ]
I, INFO -- : Triggering 'test'
BLOCK RUNNING TEST
I, INFO -- : Triggering 'test'
BLOCK RUNNING TEST

After a good amount of debugging I found it was because in my development.rb file I had:经过大量调试后,我发现这是因为在我的 development.rb 文件中我有:

config.eager_load = true

Which, combined with the其中,结合

require './config/boot'
require './config/environment'

Ran the clock file twice.运行时钟文件两次。 I believe this is because I'm preloading the app (eager_load), and then loading again with the require statements?我相信这是因为我正在预加载应用程序 (eager_load),然后使用 require 语句再次加载?

Anyways, the eager_load is ignored when clockwork is ran from my procfile (tested with $ heroku local), so it works fine.无论如何,当从我的 procfile 运行时钟时(用 $ heroku local 测试)时,eager_load 被忽略,所以它工作正常。

Hope this helps anyone as I was stuck on this for a while!希望这可以帮助任何人,因为我已经坚持了一段时间!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM