如何通过capistrano 3运行自定义rake任务? [英] How to run custom rake task via capistrano 3?
问题描述
我可以通过capistrano在远程服务器上运行rake命令。
which way, i can run rake commands via capistrano on remote server.
例如,我有一个 lib / task / reparse.rake
某些方法
for example i have a lib/task/reparse.rake
with some methods
desc "it's take csv file, makes some changes and fill db with this info"
task :example1 => :environment do
require 'csv'
rows_to_insert = []
# some actions
# ...
end
在本地服务器上都很好-我只是运行 rake reparse:example1
并且它的工作(正确填充数据库)。
所以问题是-部署后如何在真实主机上运行此命令?
on local server all is fine - i just run rake reparse:example1
and it's work(fill db correctly).
so question is - how can i run this command on real hosting, after deploy?
我使用rails 4.1 + capistrano 3。
i'am using rails 4.1 + capistrano 3.
PS网站上的示例对我不起作用
我如何从Capistrano运行rake任务?
P.S. examples from site not work for me How do I run a rake task from Capistrano?
如果我尝试 cap production rake:invoke task = reparse:land
失败,原因是:
if i try cap production rake:invoke task=reparse:land
it fails with:
cap aborted!
Don't know how to build task 'rake:invoke'
一些修复
some fixes
namespace :somenamespace do
task :runrake do
on roles(:all), in: :sequence, wait: 5 do
within release_path do
execute :rake, ENV['task'], "RAILS_ENV=production"
end
end
end
end
通过
cap production somenamespace:runrake task=custom_task_file:custom_method1
推荐答案
基于 capistrano / rails
gem: https://github.com/capistrano/rails/blob/master/lib/capistrano/ task / migrations.rake
namespace :somenamespace do
task :runrake do
on roles(:all) do
within release_path do
with rails_env: fetch(:rails_env) do
execute :rake, ask :task
end
end
end
end
end
这篇关于如何通过capistrano 3运行自定义rake任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!