启动Sidekiq队列时的循环依赖 [英] Circular dependency when Starting Sidekiq Queue

查看:85
本文介绍了启动Sidekiq队列时的循环依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

加载sidekiq队列时出现以下错误:

I get the following error when loading a sidekiq queue:

RuntimeError: Circular dependency detected while autoloading constant FileProcessor
/Users/johnmcauley/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:492:in `load_missing_constant'
/Users/johnmcauley/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:184:in `const_missing'
/Users/johnmcauley/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:526:in `load_missing_constant'
/Users/johnmcauley/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:184:in `const_missing'
/Users/johnmcauley/workspace/wripl-capture/lib/wripl_article.rb:23:in `build_from_crawled_page'
/Users/johnmcauley/workspace/wripl-capture/app/workers/article_worker.rb:7:in `perform'
/Users/johnmcauley/.rvm/gems/ruby-2.2.2/gems/sidekiq-3.4.1/lib/sidekiq/processor.rb:75:in `execute_job'
/Users/johnmcauley/.rvm/gems/ruby-2.2.2/gems/sidekiq-3.4.1/lib/sidekiq/processor.rb:52:in `block (2 levels) in process'
/Users/johnmcauley/.rvm/gems/ruby-2.2.2/gems/sidekiq-3.4.1/lib/sidekiq/middleware/chain.rb:127:in `block in invoke'
/Users/johnmcauley/.rvm/gems/ruby-2.2.2/gems/sidekiq-3.4.1/lib/sidekiq/middleware/server/active_record.rb:6:in `call'
/Users/johnmcauley/.rvm/gems/ruby-2.2.2/gems/sidekiq-3.4.1/lib/sidekiq/middleware/chain.rb:129:in `block in invoke'
/Users/johnmcauley/.rvm/gems/ruby-2.2.2/gems/sidekiq-3.4.1/lib/sidekiq/middleware/server/retry_jobs.rb:74:in `call'
/Users/johnmcauley/.rvm/gems/ruby-2.2.2/gems/sidekiq-3.4.1/lib/sidekiq/middleware/chain.rb:129:in `block in invoke'
/Users/johnmcauley/.rvm/gems/ruby-2.2.2/gems/sidekiq-failures-0.4.4/lib/sidekiq/failures/middleware.rb:9:in `call'
/Users/johnmcauley/.rvm/gems/ruby-2.2.2/gems/sidekiq-3.4.1/lib/sidekiq/middleware/chain.rb:129:in `block in invoke'
/Users/johnmcauley/.rvm/gems/ruby-2.2.2/gems/sidekiq-3.4.1/lib/sidekiq/middleware/server/logging.rb:15:in `block in call'
/Users/johnmcauley/.rvm/gems/ruby-2.2.2/gems/sidekiq-3.4.1/lib/sidekiq/logging.rb:30:in `with_context'
/Users/johnmcauley/.rvm/gems/ruby-2.2.2/gems/sidekiq-3.4.1/lib/sidekiq/middleware/server/logging.rb:11:in `call'
/Users/johnmcauley/.rvm/gems/ruby-2.2.2/gems/sidekiq-3.4.1/lib/sidekiq/middleware/chain.rb:129:in `block in invoke'
/Users/johnmcauley/.rvm/gems/ruby-2.2.2/gems/sidekiq-3.4.1/lib/sidekiq/middleware/chain.rb:132:in `call'
/Users/johnmcauley/.rvm/gems/ruby-2.2.2/gems/sidekiq-3.4.1/lib/sidekiq/middleware/chain.rb:132:in `invoke'
/Users/johnmcauley/.rvm/gems/ruby-2.2.2/gems/sidekiq-3.4.1/lib/sidekiq/processor.rb:51:in `block in process'
/Users/johnmcauley/.rvm/gems/ruby-2.2.2/gems/sidekiq-3.4.1/lib/sidekiq/processor.rb:98:in `stats'
/Users/johnmcauley/.rvm/gems/ruby-2.2.2/gems/sidekiq-3.4.1/lib/sidekiq/processor.rb:50:in `process'
/Users/johnmcauley/.rvm/gems/ruby-2.2.2/gems/celluloid-0.16.0/lib/celluloid/calls.rb:26:in `public_send'
/Users/johnmcauley/.rvm/gems/ruby-2.2.2/gems/celluloid-0.16.0/lib/celluloid/calls.rb:26:in `dispatch'
/Users/johnmcauley/.rvm/gems/ruby-2.2.2/gems/celluloid-0.16.0/lib/celluloid/calls.rb:122:in `dispatch'
/Users/johnmcauley/.rvm/gems/ruby-2.2.2/gems/celluloid-0.16.0/lib/celluloid/cell.rb:60:in `block in invoke'
/Users/johnmcauley/.rvm/gems/ruby-2.2.2/gems/celluloid-0.16.0/lib/celluloid/cell.rb:71:in `block in task'
/Users/johnmcauley/.rvm/gems/ruby-2.2.2/gems/celluloid-0.16.0/lib/celluloid/actor.rb:357:in `block in task'
/Users/johnmcauley/.rvm/gems/ruby-2.2.2/gems/celluloid-0.16.0/lib/celluloid/tasks.rb:57:in `block in initialize'
/Users/johnmcauley/.rvm/gems/ruby-2.2.2/gems/celluloid-0.16.0/lib/celluloid/tasks/task_fiber.rb:15:in `block in create'

FileProcessor是lib中的常量。

FileProcessor is a constant in lib.

我加载lib并工作人员使用:

I load lib and workers using:

    config.autoload_paths += %W(
        #{config.root}/app/workers
        #{config.root}/lib
    )

文件处理器类为:

class FileProcessor

def self.update_totals(source_id, update_type)

    total = Total.first
    if total == nil
       total = Total.new
    end

    source = Source.find(source_id)

    if update_type.to_s == "ARTICLE"
      source.number_of_articles = source.number_of_articles + 1
      total.number_of_articles = total.number_of_articles + 1
    elsif update_type.to_s == "PAGE"
      source.number_of_pages = source.number_of_pages + 1
      total.number_of_pages = total.number_of_pages + 1
    elsif update_type.to_s == "RSS" 
      source.number_of_rss_articles = source.number_of_rss_articles + 1
      total.number_of_rss_articles = total.number_of_rss_articles + 1
    end

    source.save
    total.save
end
end

我环顾四周,但找不到解决此问题的方法。

I have looked around but cannot find a solution to this problem.

有什么建议吗?

推荐答案

好,所以这是一个authoload / eagerload问题。我发现有关GH处理此问题的一些讨论。我仍然必须在生产中进行测试,但要添加:

Ok, so this was an authoload/eagerload issue. I found some discussion on GH dealing with the issue. I still have to test in production but adding:

config.autoload_paths += %W(
    #{config.root}/app/workers
    #{config.root}/lib
)
config.eager_load_paths += %W(
    #{config.root}/app/workers
    #{config.root}/lib
)

至application.rb已修复问题。

to application.rb fixed the problem.

感谢:

https://github.com/mperham/sidekiq/issues/2060
https://github.com/mperham/sidekiq/issues/1927
http://blog.arkency.com/2014/11/dont-forget-about-eager-load-when -extending-autoload /

这篇关于启动Sidekiq队列时的循环依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆