Where should I put background processes in rails?

泄露秘密 提交于 2019-12-06 13:29:09

To control the scheduler I would create a config/initializers/task_scheduler.rb:

task_scheduler = Rufus::Scheduler.start_new  

task_scheduler.every("1m") do  
   Something.to_do! # Do something every minute! 
end

Now for the Something.to_do code, that sort of depends on what it does. Perhaps it is a data model and it should go in the app/models directory, but if it is something more generic you might want to place it in lib/. If you wind up with a number of scheduled tasks you might want to create a app/scheduled_tasks directory, but that might be overkill for just one file.

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