【问题标题】:workling doesnt work when the database is down in my rails app当我的 Rails 应用程序中的数据库关闭时,工作不起作用
【发布时间】:2010-11-26 22:07:30
【问题描述】:

我想安排我的工作人员使用 cron 作业定期检查数据库连接(比如 5 分钟)并相应地更新内存缓存键。所以在我的应用程序中,如果我找到要设置的 memcache 变量。然后,当数据库启动时,我会以不同的方式呈现我的页面。

但问题是,当数据库关闭时,worker 不会启动。当数据库启动时。它正确地发现存在数据库连接并更新 memcache 变量并且一切正常。

我不知道,为什么当数据库关闭时,worker 不启动。 我快到最后期限了。非常感谢任何帮助!

更新:

这是我在工作不启动时得到的错误

/apps/Symantec/shasta/website/install/local/ruby-1.8.7-p299/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/connection_adapters/mysql_adapter.rb: 527:在real_connect': Can't connect to MySQL server on '10.223.2.50' (111) (Mysql::Error) from /apps/Symantec/shasta/website/vendor/plugins/workling/script/../lib/workling/starling/poller.rb:35:in加入' 来自 /apps/Symantec/shasta/website/vendor/plugins/workling/script/../lib/workling/starling/poller.rb:35:in listen' from /apps/Symantec/shasta/website/vendor/plugins/workling/script/../lib/workling/starling/poller.rb:35:ineach' 来自 /apps/Symantec/shasta/website/vendor/plugins/workling/script/../lib/workling/starling/poller.rb:35:in listen' from /apps/Symantec/shasta/website/vendor/plugins/workling/script/listen.rb:19 from /apps/Symantec/shasta/website/install/local/ruby-1.8.7-p299/lib/ruby/gems/1.8/gems/daemons-1.1.0/lib/daemons/application.rb:203:inload' 来自 /apps/Symantec/shasta/website/install/local/ruby-1.8.7-p299/lib/ruby/gems/1.8/gems/daemons-1.1.0/lib/daemons/application.rb:203:in @ 987654324@start' 来自 /apps/Symantec/shasta/website/install/local/ruby-1.8.7-p299/lib/ruby/gems/1.8/gems/daemons-1.1.0/lib/daemons/monitor.rb:51:in @ 987654325@fork' 来自 /apps/Symantec/shasta/website/install/local/ruby-1.8.7-p299/lib/ruby/gems/1.8/gems/daemons-1.1.0/lib/daemons/monitor.rb:51:in @ 987654326@每个' 来自 /apps/Symantec/shasta/website/install/local/ruby-1.8.7-p299/lib/ruby/gems/1.8/gems/daemons-1.1.0/lib/daemons/monitor.rb:45:in @ 987654327@loop' 来自 /apps/Symantec/shasta/website/install/local/ruby-1.8.7-p299/lib/ruby/gems/1.8/gems/daemons-1.1.0/lib/daemons/monitor.rb:44:in @ 987654328@start_with_pidfile' 来自 /apps/Symantec/shasta/website/install/local/ruby-1.8.7-p299/lib/ruby/gems/1.8/gems/daemons-1.1.0/lib/daemons/monitor.rb:64:in @ 987654329@start_with_pidfile' 来自 /apps/Symantec/shasta/website/install/local/ruby-1.8.7-p299/lib/ruby/gems/1.8/gems/daemons-1.1.0/lib/daemons/monitor.rb:111:in @ 987654330@create_monitor' 来自 /apps/Symantec/shasta/website/install/local/ruby-1.8.7-p299/lib/ruby/gems/1.8/gems/daemons-1.1.0/lib/daemons/application.rb:283:in @ 987654331@run' 来自 /apps/Symantec/shasta/website/install/local/ruby-1.8.7-p299/lib/ruby/gems/1.8/gems/daemons-1.1.0/lib/daemons.rb:143:in run' from /apps/Symantec/shasta/website/install/local/ruby-1.8.7-p299/lib/ruby/gems/1.8/gems/daemons-1.1.0/lib/daemons/cmdline.rb:112:in称呼' 来自 /apps/Symantec/shasta/website/install/local/ruby-1.8.7-p299/lib/ruby/gems/1.8/gems/daemons-1.1.0/lib/daemons/cmdline.rb:112:in @ 987654333@run' 来自脚本/workling_starling_client:17

【问题讨论】:

    标签: ruby-on-rails workling


    【解决方案1】:

    也许工作人员在启动时(总是)尝试连接到数据库并抛出异常?您是否有任何工人记录的错误?

    你是在 Rails 中编写你的 worker 的吗?也许写一个shell脚本,当worker无法启动时假设数据库已关闭?

    更新:在您的堆栈跟踪中有起点:script/workling_starling_client:17。第 17 行有什么?

    正如第一行(异常消息本身)所说“real_connect': Can't connect to MySQL server on '10.223.2.50' (111) (Mysql::Error)” 然后如果您将第 17 行(可能还有更多)包装在“救援”块中,并检查错误消息是否有您正在寻找的答案就足够了:

    (当然,不要停在这里。继续检查,因为没有异常意味着连接已建立)

    begin
      line_17_is_here
    rescue => e
      if e.message =~ /Can't connect to MySQL/
        handle_your_no_connection_state
      else
        raise e
      end
    end
    

    问题是:没有ActiveRecord你能处理无连接状态吗?

    【讨论】:

    • 我正在考虑为此完全放弃工作。而是在 scripts/check.rb 中运行一个后台 ruby​​ scirpt,它会更新我的网站检查的 memcache 变量,以查看 db 是否已连接。但在我的 ruby​​ 脚本中,如果我使用 require 'memcache' 。它抛出一个和 loadError .cant find memcache.
    猜你喜欢
    • 1970-01-01
    • 2023-01-16
    • 2017-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多