LoginSignup
1
0

More than 5 years have passed since last update.

BeanstalkでRailsのDelayedJobでメール送信がエラー

Posted at

エラー

ActionMailerを使ってメール送信を作っていて、とりあえずお手軽にDelayedJobを使ってバックグラウンド送信しようとしていた時に出たエラーです。
内容は delayed_jobs テーブルの last_errorというカラムに保存されていました。

can not load translations from 
/var/app/ondeck/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.4/lib/active_support/locale/en.yml: 
#<Errno::ENOENT: No such file or directory @ rb_sysopen - 
/var/app/ondeck/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.4/lib/active_support/locale/en.yml> 
.......

原因

エラーをそのまま見ると、該当のファイルがない的なことなんですが、
そもそも /var/app/ondeck というのがミソでした。

Beanstalkの仕組み

BeanstalkでBrue-greenデプロイを実現するために、アプリのデプロイは二つのディレクトリを使って行われています。

/var/app/ondeck →アプリがデプロイされるディレクトリ
/var/app/current →実際にアプリが動くディレクトリ

ondeck にデプロイされたアプリが current にコピーされるという流れみたいです。

Beanstalkでアプリをデプロイした時に、delayed_jobの起動をやっていたのですが、
その段階ではondeckにビルドされていて、メール送信時にondeckのディレクトリを探しに行ってたのが直接の原因みたいでした。

対策

デプロイ時のdelayed_jobの起動を下記のようなコマンドで実行してあげることで正常にメール送信できるようになりました。

03_container_command.config
06-delayed_job:
    command: RAILS_ENV=production ./bin/delayed_job --pid-dir=/var/app/support/pids restart
    cwd: /var/app/current

参考

http://junkheap.net/blog/2013/05/20/elastic-beanstalk-post-deployment-scripts/
https://www.codesd.com/item/how-to-restart-delayed-job-automatically-when-deploying-a-track-project-on-amazon-elastic-beanstalk.html

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0