アプリでバックグラウンドタスクを実行するために遅延ジョブを使用しています。それはいくつかのことをしてからメールを送ります。これは、遅延ジョブとして実行されたコードブロックの例です。
def task
# do stuff
AppMailer.post.some_template(@variable)
end
これは正常に機能しています。正しいディレクトリsome_template.text.plain.erbにテンプレートがあります。これによりMissingTemplate例外が発生するのがわかり始めました。これにより、遅延ジョブが停止し、指定された時間が経過すると再試行します(遅延ジョブで例外が発生した場合に予想されます)。これが2〜3回失敗して正常に配信される場合もあれば、例外が発生しない場合もあります。テンプレートが存在しない場合、次の試行で正常に検出するにはどうすればよいですか?
テンプレートを探しているときにエラーが発生し、この問題.erb
が発生しています。plain.text.erb
これが断続的な問題を引き起こしている理由はありますか?例外を発生させるよりもメールを送信したくないので、メールの送信をレスキューブロックでラップしようとしました。
def task
# do stuff
begin
AppMailer.post.some_template(@variable)
rescue ActionView::MissingTemplate => e
# do stuff
end
end
しかし、例外はまだ発生しています。遅延した仕事は、このレスキューブロックの動作を停止させる可能性のあることをしますか?
これがスタックトレースです
Error:
Missing template app_mailer/some_template.erb in view path app/views:vendor/plugins/tolk/app/views
/data/app/shared/bundled_gems/ruby/1.8/gems/actionpack-2.3.14/lib/action_view/paths.rb:74:in `find_template'
/data/app/shared/bundled_gems/ruby/1.8/gems/actionpack-2.3.14/lib/action_view/base.rb:264:in `render'
/data/app/shared/bundled_gems/ruby/1.8/gems/actionmailer-2.3.14/lib/action_mailer/base.rb:600:in `render'
/data/app/shared/bundled_gems/ruby/1.8/gems/actionmailer-2.3.14/lib/action_mailer/base.rb:586:in `render_message'
/data/app/shared/bundled_gems/ruby/1.8/gems/actionmailer-2.3.14/lib/action_mailer/base.rb:526:in `create!'
/data/app/shared/bundled_gems/ruby/1.8/gems/actionmailer-2.3.14/lib/action_mailer/base.rb:485:in `initialize'
/data/app/shared/bundled_gems/ruby/1.8/gems/actionmailer-2.3.14/lib/action_mailer/base.rb:427:in `new'
/data/app/shared/bundled_gems/ruby/1.8/gems/actionmailer-2.3.14/lib/action_mailer/base.rb:427:in `method_missing'
/data/app/releases/20121127213524/app/models/mail_delivery.rb:55:in `send'
/data/app/releases/20121127213524/app/models/mail_delivery.rb:55:in `serialize_mail'
/data/app/shared/bundled_gems/ruby/1.8/gems/activesupport-2.3.14/lib/active_support/callbacks.rb:178:in `send'
/data/app/shared/bundled_gems/ruby/1.8/gems/activesupport-2.3.14/lib/active_support/callbacks.rb:178:in `evaluate_method'
/data/app/shared/bundled_gems/ruby/1.8/gems/activesupport-2.3.14/lib/active_support/callbacks.rb:166:in `call'
/data/app/shared/bundled_gems/ruby/1.8/gems/activesupport-2.3.14/lib/active_support/callbacks.rb:93:in `run'
/data/app/shared/bundled_gems/ruby/1.8/gems/activesupport-2.3.14/lib/active_support/callbacks.rb:92:in `each'
/data/app/shared/bundled_gems/ruby/1.8/gems/activesupport-2.3.14/lib/active_support/callbacks.rb:92:in `send'
/data/app/shared/bundled_gems/ruby/1.8/gems/activesupport-2.3.14/lib/active_support/callbacks.rb:92:in `run'
/data/app/shared/bundled_gems/ruby/1.8/gems/activesupport-2.3.14/lib/active_support/callbacks.rb:276:in `run_callbacks'
/data/app/shared/bundled_gems/ruby/1.8/gems/activerecord-2.3.14/lib/active_record/callbacks.rb:344:in `callback'
/data/app/shared/bundled_gems/ruby/1.8/gems/activerecord-2.3.14/lib/active_record/callbacks.rb:265:in `create'
/data/app/shared/bundled_gems/ruby/1.8/gems/activerecord-2.3.14/lib/active_record/base.rb:2927:in `create_or_update_without_callbacks'
/data/app/shared/bundled_gems/ruby/1.8/gems/activerecord-2.3.14/lib/active_record/callbacks.rb:250:in `create_or_update'
/data/app/shared/bundled_gems/ruby/1.8/gems/activerecord-2.3.14/lib/active_record/base.rb:2577:in `save_without_validation'
/data/app/shared/bundled_gems/ruby/1.8/gems/activerecord-2.3.14/lib/active_record/validations.rb:1089:in `save_without_dirty'
/data/app/shared/bundled_gems/ruby/1.8/gems/activerecord-2.3.14/lib/active_record/dirty.rb:79:in `save_without_transactions'
/data/app/shared/bundled_gems/ruby/1.8/gems/activerecord-2.3.14/lib/active_record/transactions.rb:229:in `send'
/data/app/shared/bundled_gems/ruby/1.8/gems/activerecord-2.3.14/lib/active_record/transactions.rb:229:in `with_transaction_returning_status'
/data/app/shared/bundled_gems/ruby/1.8/gems/activerecord-2.3.14/lib/active_record/connection_adapters/abstract/database_statements.rb:136:in `transaction'
/data/app/shared/bundled_gems/ruby/1.8/gems/activerecord-2.3.14/lib/active_record/transactions.rb:182:in `transaction_without_trace_ActiveRecord_self_name_transaction'
/data/app/shared/bundled_gems/ruby/1.8/gems/newrelic_rpm-3.4.0.1/lib/new_relic/agent/method_tracer.rb:491:in `transaction'
/data/app/shared/bundled_gems/ruby/1.8/gems/newrelic_rpm-3.4.0.1/lib/new_relic/agent/method_tracer.rb:242:in `trace_execution_scoped'
/data/app/shared/bundled_gems/ruby/1.8/gems/newrelic_rpm-3.4.0.1/lib/new_relic/agent/method_tracer.rb:486:in `transaction'
/data/app/shared/bundled_gems/ruby/1.8/gems/activerecord-2.3.14/lib/active_record/transactions.rb:228:in `with_transaction_returning_status'
/data/app/shared/bundled_gems/ruby/1.8/gems/activerecord-2.3.14/lib/active_record/transactions.rb:196:in `save'
/data/app/shared/bundled_gems/ruby/1.8/gems/activerecord-2.3.14/lib/active_record/transactions.rb:208:in `rollback_active_record_state!'
/data/app/shared/bundled_gems/ruby/1.8/gems/activerecord-2.3.14/lib/active_record/transactions.rb:196:in `save'
/data/app/shared/bundled_gems/ruby/1.8/gems/activerecord-2.3.14/lib/active_record/base.rb:727:in `create'
/data/app/releases/20121127213524/app/models/mail_delivery.rb:88:in `method_missing'
/data/app/releases/20121127213524/lib/job_manifest.rb:670:in `notify_user_of_upload_without_audit'
/data/app/releases/20121127213524/lib/job_manifest.rb:6:in `send'
/data/app/releases/20121127213524/lib/job_manifest.rb:6:in `notify_user_of_upload_with_audit'
/data/app/releases/20121127213524/lib/job_manifests/app_send_job.rb:43:in `notify_user_of_upload'
/data/app/releases/20121127213524/lib/job_manifests/app_send_job.rb:43:in `extended'
/data/app/releases/20121127213524/lib/job_manifest.rb:102:in `preflight_completed_changed_delayed'
/data/app/shared/bundled_gems/ruby/1.8/gems/delayed_job-2.0.7/lib/delayed/performable_method.rb:35:in `send'
/data/app/shared/bundled_gems/ruby/1.8/gems/delayed_job-2.0.7/lib/delayed/performable_method.rb:35:in `perform'
/data/app/shared/bundled_gems/ruby/1.8/gems/delayed_job-2.0.7/lib/delayed/backend/base.rb:74:in `invoke_job'
/data/app/shared/bundled_gems/ruby/1.8/gems/delayed_job-2.0.7/lib/delayed/worker.rb:122:in `run'
/usr/lib64/ruby/1.8/timeout.rb:67:in `timeout'
/data/app/shared/bundled_gems/ruby/1.8/gems/delayed_job-2.0.7/lib/delayed/worker.rb:122:in `run'
/usr/lib64/ruby/1.8/benchmark.rb:308:in `realtime'
/data/app/shared/bundled_gems/ruby/1.8/gems/delayed_job-2.0.7/lib/delayed/worker.rb:121:in `run'
/data/app/shared/bundled_gems/ruby/1.8/gems/delayed_job-2.0.7/lib/delayed/worker.rb:173:in `reserve_and_run_one_job'
/data/app/shared/bundled_gems/ruby/1.8/gems/delayed_job-2.0.7/lib/delayed/worker.rb:106:in `work_off'
/data/app/shared/bundled_gems/ruby/1.8/gems/delayed_job-2.0.7/lib/delayed/worker.rb:105:in `times'
/data/app/shared/bundled_gems/ruby/1.8/gems/delayed_job-2.0.7/lib/delayed/worker.rb:105:in `work_off'
/data/app/shared/bundled_gems/ruby/1.8/gems/delayed_job-2.0.7/lib/delayed/worker.rb:80:in `start'
/usr/lib64/ruby/1.8/benchmark.rb:308:in `realtime'
/data/app/shared/bundled_gems/ruby/1.8/gems/delayed_job-2.0.7/lib/delayed/worker.rb:79:in `start'
/data/app/shared/bundled_gems/ruby/1.8/gems/delayed_job-2.0.7/lib/delayed/worker.rb:76:in `loop'
/data/app/shared/bundled_gems/ruby/1.8/gems/delayed_job-2.0.7/lib/delayed/worker.rb:76:in `start'
/data/app/shared/bundled_gems/ruby/1.8/gems/delayed_job-2.0.7/lib/delayed/command.rb:100:in `run'
(eval):1
/data/app/current/script/runner:3:in `eval'
/data/app/shared/bundled_gems/ruby/1.8/gems/rails-2.3.14/lib/commands/runner.rb:48
/data/app/current/script/runner:3:in `require'
/data/app/current/script/runner:3
ここにはいくつか問題があることは知っていますが、アドバイスをいただければ幸いです。