哪个方式,我可以通过capistrano远程服务器上运行rake命令.
例如我有一个lib / task / reparse.rake与一些方法
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
它的工作(正确填充db).
所以问题是 – 在实际的托管之后如何运行这个命令?
我使用轨道4.1 capistrano 3.
附:网站上的例子不适合我
How do I run a rake task from Capistrano?
如果我尝试盖生产耙:调用任务= reparse:土地
它失败了:
cap aborted! Don't know how to build task 'rake:invoke'
一些修复
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/tasks/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