我正确设置了whenever
GEM设置。如何从whenever
schedule.rb
运行capistrano
?
我的时间表。rb
every 1.minute, roles: [:app] do
# how to run here a capistrano task
# invoke 'my_app:test'
end
我的Capistrano任务:
namespace :my_app do
desc 'test'
task :test do
on roles(:web) do
puts "the task runs"
end
end
end
或应该将该任务移至rake
任务中。我应该在whenever
和capistrano
中运行该耙子任务吗?
jan,您可能会发现文档非常有用https://github.com/javan/whenever。下面的代码示例 - 我刚刚从文档复制并进行了编辑。
schedule.rb
# run this task only on servers with the :app role in Capistrano
# see Capistrano roles section below
every :day, at: '12:20am', roles: [:web] do
rake "app_server:task"
end
lib/tasks/test_task.rb
namespace :my_app do
desc 'test'
task :test do
puts "the task runs"
end
end
我相信,创建耙任务并随时运行它会更容易。您可以选择角色,因此基本上您不需要使用Capistrano任务(我相信您只想仅仅因为角色而使用它)。
我建议您的后一个选项,将逻辑移至耙子任务,然后随时随地执行它。这样做会变得更加容易,更干净。