0

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

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

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

更新:

这是我在工作没有开始时得到的错误

/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:inreal_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 start_load' 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:296:instart' from /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:inwatch' from /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来自 /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 的 fork :在watch' from /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每个'来自 /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:45watch' from /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来自/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:在watch' from /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:84:instart_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 fork' from /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:instart_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:在start' 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_group.rb:149:in来自/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的create_monitor:从start' from /apps/Symantec/shasta/website/install/local/ruby-1.8.7-p299/lib/ruby/gems/1.8/gems/daemons-1.1.0/lib/daemons/controller.rb:70:in/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 的调用:在catch_exceptions' from /apps/Symantec/shasta/website/install/local/ruby-1.8.7-p299/lib/ruby/gems/1.8/gems/daemons-1.1.0/lib/daemons.rb:142:in运行中'来自脚本/workling_starling_client:17

4

1 回答 1

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,你能处理无连接状态吗?

于 2010-11-26T12:56:59.810 回答