自动执行 rake 任务以在 heroku 上启动时运行? [英] Automate a rake task to run on boot on heroku?

查看:44
本文介绍了自动执行 rake 任务以在 heroku 上启动时运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设有一个任务

rake startupscript

应该在应用启动时运行,我们如何在 heroku 上实现自动化?

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

我知道有一个 heroku 调度程序,但它会每 10 分钟运行一次任务,而不是在启动时只运行一次.我也知道 Procfile 并且相信这可以是一个解决方案,虽然我还不知道如何实现(可能更重要的是,我不想冒险破坏可以通过 Procfile 配置的任何其他内容,例如网络服务器等).许多 Procfile 文档都专注于使用它来更改 Web 服务器,而不是应用级别的 rake 任务.

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.

如何使 rake 任务在启动时运行?

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

推荐答案

在启动应用程序服务之前,您可以将这样的内容添加到 Procfile 中

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}

任何标记为 release 的东西都会在启动脚本运行之前运行

Anything tagged as release will run before the startup script runs

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

这篇关于自动执行 rake 任务以在 heroku 上启动时运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆