Rails 3/delayed_job - Wanted: Basic example of delayed mail

偶尔善良 提交于 2019-11-30 07:33:36

I agree with andrea - I was having this exact problem, and after switching my local development database from sqlite to mysql, I can run code like

Emailer.delay({:run_at => 5.minutes.from_now}).welcome(@user)

and it sends the email 5 minutes later. Note that you might need a bigger delay than five minutes (in case of time zone weirdness) to be sure it is working.

I found in Rails 3 with mongoid that removing the handle_asynchronously line gets it to work. I was having all kinds of problems, and it appeared that delayed_job wasn't recognizing any objects within my Emailer class. Removing handle_asynchronously fixed it.

andrea

Both using the .delay method and setting handle_asynchronously :test_mail is redundant. Try removing the .delay method from your code. use simply

Testmailer.test_mail   # without .deliver due to a delayed_job issue

However, I ran some test on your configuration and when using sqlite, run_at is simply ignored (do not know why), but when using mysql2 everything works fine.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!