Cron 作业未在 gem 之前更新
Cron job not being updated by whenever gem
有一系列 rake 任务应该由 whenever gem 翻译到 cron 文件中,我想知道为什么 takes 显示指向旧版本。
无法断言 whenever 以某种方式处于活动状态,即使它列在 gem 文件(和关联的锁定文件)中并且部署指的是部署中的 whenever,如下所示:
tar: DEBUG [1f7d4e56] bin/whenever: time stamp 2016-01-08 15:01:20 is 88.787104175 s in the future
更新 正在检查 bundle exec whenever -v
returns 正确的版本。 那里需要 bundle exec...
Capfile 在调用捆绑器和 rails 之后包含 require "whenever/capistrano"
。
require 'capistrano/bundler'
require 'capistrano/rails'
require 'whenever/capistrano'
注意:这正在开发模式下进行测试。
我在使用 Capistrano 时遇到了同样的问题,我通过自定义部署 shell 脚本解决了这个问题,cap production deploy
是许多命令中的一个,然后在里面包含 cap production cron:regen;
这个脚本我称为 deploy.sh,deploy.rb
中的命令是:
namespace :cron do
desc "restart cron"
task :regen do
on roles(:app) do |host|
rails_env = fetch(:stage)
execute_interactively "crontab -r;bundle exec whenever --update-crontab;crontab -l;"
end
end
end
def execute_interactively(command)
port = fetch(:port) || 22
exec "ssh root@#{fetch(:ip)} -t 'cd SERVER_PATH_OF_YOUR_APP && #{command}'"
end
我将这些函数用于所有类型的不同命令,因为 Capistrano 使用的许多本机插件仍然给我带来问题。
功能性答案。 instructions 具有误导性 如果您不需要在 capistrano 部署的不同服务器上执行不同的作业 运行,那么您现在可以安全地停止阅读,一切都应该以同样的方式工作总是有。 继续阅读。
块嵌套在该语句之后。角色默认为 [:db]。因此可能有两种错误来源:
- 不同的job_roles在不同的机器上没有指定schedule.rb
- 检查你的环境文件。如果 "db" 未列出,则 not 将在任何时候触发。
如果您对 whenever/capistrano 不满意,您可以自己创建一个简单的 Capistrano 任务来更新 cron 作业:
namespace :deploy do
desc "Update crontab with whenever"
task :update_cron do
on roles(:app) do
within current_path do
execute :bundle, :exec, "whenever --update-crontab #{fetch(:application)}"
end
end
end
after :finishing, 'deploy:update_cron'
end
代码部署完成后将调用该任务。
有一系列 rake 任务应该由 whenever gem 翻译到 cron 文件中,我想知道为什么 takes 显示指向旧版本。
无法断言 whenever 以某种方式处于活动状态,即使它列在 gem 文件(和关联的锁定文件)中并且部署指的是部署中的 whenever,如下所示:
tar: DEBUG [1f7d4e56] bin/whenever: time stamp 2016-01-08 15:01:20 is 88.787104175 s in the future
更新 正在检查 bundle exec whenever -v
returns 正确的版本。 那里需要 bundle exec...
Capfile 在调用捆绑器和 rails 之后包含 require "whenever/capistrano"
。
require 'capistrano/bundler'
require 'capistrano/rails'
require 'whenever/capistrano'
注意:这正在开发模式下进行测试。
我在使用 Capistrano 时遇到了同样的问题,我通过自定义部署 shell 脚本解决了这个问题,cap production deploy
是许多命令中的一个,然后在里面包含 cap production cron:regen;
这个脚本我称为 deploy.sh,deploy.rb
中的命令是:
namespace :cron do
desc "restart cron"
task :regen do
on roles(:app) do |host|
rails_env = fetch(:stage)
execute_interactively "crontab -r;bundle exec whenever --update-crontab;crontab -l;"
end
end
end
def execute_interactively(command)
port = fetch(:port) || 22
exec "ssh root@#{fetch(:ip)} -t 'cd SERVER_PATH_OF_YOUR_APP && #{command}'"
end
我将这些函数用于所有类型的不同命令,因为 Capistrano 使用的许多本机插件仍然给我带来问题。
功能性答案。 instructions 具有误导性 如果您不需要在 capistrano 部署的不同服务器上执行不同的作业 运行,那么您现在可以安全地停止阅读,一切都应该以同样的方式工作总是有。 继续阅读。
块嵌套在该语句之后。角色默认为 [:db]。因此可能有两种错误来源:
- 不同的job_roles在不同的机器上没有指定schedule.rb
- 检查你的环境文件。如果 "db" 未列出,则 not 将在任何时候触发。
如果您对 whenever/capistrano 不满意,您可以自己创建一个简单的 Capistrano 任务来更新 cron 作业:
namespace :deploy do
desc "Update crontab with whenever"
task :update_cron do
on roles(:app) do
within current_path do
execute :bundle, :exec, "whenever --update-crontab #{fetch(:application)}"
end
end
end
after :finishing, 'deploy:update_cron'
end
代码部署完成后将调用该任务。