Ruby / Rails - 运行部署后任务的更好方法?
我们使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试 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.
我想到了两种方法
Two approaches come to my mind
你应该尝试一下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.