0

cron ジョブを使用してワーカーをスケジュールし、データベース接続を定期的に (たとえば 5 分程度) チェックし、それに応じて memcache キーを更新したいと考えています。私のアプリで memcache 変数が設定されていることがわかった場合。データベースが稼働しているときに、ページを別の方法でレンダリングします。

しかし問題は、データベースがダウンしているときにワーカーが起動しないことです。データベースが起動したとき。データベース接続が存在することを正しく検出し、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:in 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から参加' from /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' 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: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: /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:45:inから: 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: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: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 の start_with_pidfile 内:64: 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: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 の start_with_pidfile 内。 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: in 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:inrun' 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: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 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:inrun' from script/workling_starling_client:17

4

1 に答える 1

1

たぶん、ワーカーは開始時に (常に) データベースに接続しようとし、例外をスローしますか? ワーカーによってログに記録されたエラーはありますか?

ワーカーを Rails で作成しましたか? ワーカーが起動できないときにデータベースがダウンしていると想定するシェル スクリプトを作成することはできますか?

更新: スタック トレースには開始点があります: 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 に答える