生产环境的物理架构包括多台执行不同作业(rake 任务)的机器,所有这些机器都在同一个数据库上。
其中一项工作将完成大量工作UPDATE
如果其他作业正在运行,则通常会返回 postgres 死锁的表。
我已经有一个 rake 任务来正常停止其他作业,但我只能从本地计算机执行它。
我想要实现的是:
task :big_update => :environment do
stop_tasks_on_another_servers
# do the SQL UPDATE
...
end
其中 stop_tasks_on_another_servers 应该执行rake task
在其他服务器上。
我最好的尝试是使用https://github.com/capistrano/sshkit https://github.com/capistrano/sshkit宝石。与 Capistrano 使用的相同,但我仍然缺少一步。
我正在生产机器的 Rails 控制台上尝试以下操作:
require 'sshkit/dsl'
hosts = ['machine1', 'machine2']
on hosts do
within "/home/me/project/current" do
with rails_env: :production do
rake "stop_tasks"
end
end
end
但它返回:
INFO [70a0610a] Running /usr/bin/env rake stop_tasks on machine1
SSHKit::Command::Failed: rake stdout: Nothing written
我缺少什么或者有更简单的方法来执行远程任务吗?
查看Rake 远程任务 https://github.com/seattlerb/rake-remote_task。这是一个向您展示其工作原理的片段:
require 'rake/remote_task'
set :domain, 'abc.example.com'
remote_task :foo do
run "ls"
end
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)