Automate a rake task to run on boot on heroku?

ぐ巨炮叔叔 提交于 2021-02-05 08:59:49

问题


Suppose there's a task

rake startupscript

that should run whenever the app boots, how can we automate that on heroku?

I know there's a heroku scheduler but that will run the task every 10 minutes instead of just once at boot. I also know of the Procfile and believe this can be a solution, although I do not yet know how to implement (and probably more importantly, I don't want to risk breaking anything else that can be configured via a Procfile, e.g. webserver etc). A lot of the Procfile docs focus on using it to alter web servers rather than app level rake tasks.

How can a rake task be made to run at boot?


回答1:


You can add something like this to Procfile before you start your application services

# Run pre-release-tasks here
release: bundle exec rails db:migrate
# Then run your application
web: bundle exec puma -t 5:5 -p ${PORT:-3000} -e ${RACK_ENV:-development}

Anything tagged as release will run before the startup script runs

https://devcenter.heroku.com/articles/release-phase



来源:https://stackoverflow.com/questions/64657193/automate-a-rake-task-to-run-on-boot-on-heroku

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