Best rails solution for a mailer that runs every minute

前端 未结 4 923
有刺的猬
有刺的猬 2021-01-01 01:00

I have an application that checks a database every minute for any emails that are supposed to be sent out at that time. I was thinking about making this a rake task that wou

4条回答
  •  旧时难觅i
    2021-01-01 01:15

    One really simple method would be to have a script that does..

    while true do
        check_and_send_messages()
        sleep 60
    end
    

    ..which means you are not constantly respawning the Rails environment.

    Obviously it has various flaws, but also has some benefits (for example, with your 1-Rake-per-minute, it the Rake task takes more than one minute, Rake will be running multiple times at once)

    Also, the Railscasts episodes Rake in Background, Starling and Workling, and Custom Daemon might give you some ideas (they are describing exactly this task)

提交回复
热议问题