Ruby / Rails - 运行部署后任务的更好方法?

发布于 2024-09-18 23:47:24 字数 549 浏览 5 评论 0原文

我们使用 EngineYard App Cloud 托管 Ruby on Rails 应用程序,这对我们来说非常有效。它们提供了一系列部署回调(before_restart、after_restart 等),类似于 Capistrano 的回调。

我们的应用程序中有一系列 Rake 任务,用于维护应用程序的各个部分。如果我们向数据库添加新的业务规则,我们可能需要重新加载用户关联的业务规则等。

这些任务没有硬性或快速的时间表,但我们也不希望运行每个任务在每次部署时,因为它们会减慢部署过程。

是否有任何系统允许我们定义要在下一次部署时运行的任务,类似于迁移。我心目中的理想系统将按如下方式工作:

  • 我们意识到在下一次部署时,需要运行一个任务
  • 我们通过系统安排任务
  • 在下一次部署时,系统会看到部署后任务的列表--它注意到最新的任务尚未在特定服务器上运行(就像迁移在运行时如何标记数据库一样,以便仅触发最新的未运行的迁移)——新任务被触发

任何建议关于安排这些部署后任务并让它们启动的最佳实践,除非它们已经在服务器上运行?

谢谢!

We're hosting our Ruby on Rails application with the EngineYard App Cloud, which has worked really well for us. They provide a series of deploy call backs (before_restart, after_restart, etc.) which are analogous to Capistrano's callbacks.

We have a series of Rake tasks within our application which maintain various parts of the application. If we add a new business rule to the database, we might need to reload the users' associated business rules, etc.

These are tasks that there's no hard or fast schedule for, but also we don't want to run each and every task on every deploy, because they slow down the deploy process.

Are there any systems which would allow us to define a task to be run on the next deploy, sort of like migrations. The ideal system in my mind would work as follows:

  • We realize that on the next deploy, a task will need to be run
  • We schedule the task via the system
  • On the next deploy, the system see the list of post-deploy tasks -- it notices that the most recent one has not been run on the specific server yet (as in how migrations notate the database when they're run so that only the most recent, unrun migrations are triggered) -- the new task is triggered

Any recommendations on best practices for scheduling these post-deploy tasks and have them fire off unless they've already been run on the server?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

半世晨晓 2024-09-25 23:47:24

尝试 after_party ruby​​ gem,它模仿 db:migrate 的基本操作,但用于部署后任务。部署后 (rake) 任务的创建名称类似于

lib/tasks/deployment/20130130215258_task_name.rake

您当然可以从 rake 任务中调用任何 ruby​​ 代码。文档说它支持同步和异步任务(异步任务是长时间运行的任务,您可以在应用程序启动时在后台进行)

我没有使用它,但我准备尝试一下,因为我们有类似的如您所描述的要求。

Try the after_party ruby gem which is modelled on the basic operation of db:migrate but is for post deployment tasks. Post deployment (rake) tasks are created with a name like so

lib/tasks/deployment/20130130215258_task_name.rake

You can of course call any ruby code from within the rake task. The documentation says it supports sync and async tasks (async tasks are long running tasks that you can have going on in the background while your app is starting up)

I've not used it but am about to give it a shot as we have similar requirements as you've described.

我不会写诗 2024-09-25 23:47:24

我想到了两种方法

  1. 快速/肮脏的解决方案......你可以使用迁移来做到这一点吗?创建一个 Rails 迁移,在运行 rake db:migrate 时触发任务
  2. 采用与迁移相同的方法。创建 schema_migrations 表的对等表,然后在您的 before_symlink.rb (或其他任何地方)运行尚未执行的任务,然后更新该表?

Two approaches come to my mind

  1. Quick/dirty solution...could you just use migrations to do this? Create a Rails migration that fires off the tasks when rake db:migrate is run
  2. Take the same approach as migrations. Create a peer table to the schema_migrations table, and then in your before_symlink.rb (or whereever else) run the tasks that have not been executed yet, and then update the table?
病女 2024-09-25 23:47:24

你应该尝试一下rails_tasker。它提供了一种直接的方法来自动执行部署后任务。 这里是一篇介绍如何使用的文章宝石。

You should give rails_tasker a shot. It provides a straight-forward way to automating your post-deploy tasks. Here is an article that describes how to use the gem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文