which way, i can run rake commands via capistrano on remote server.
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
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?
i'am using rails 4.1 + capistrano 3.
P.S. examples from site not work for me How do I run a rake task from Capistrano?
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
with such way it begin to execute via
cap production somenamespace:runrake task=custom_task_file:custom_method1
So I have been working on this. it seams to work well. However you need a formater to really take advantage of the code.
If you don't want to use a formatter just set the log level to to debug mode.
Cap Stuff
This is the formatter I built to work with the code above. It is based off the :textsimple built into the sshkit but it is not a bad way to invoke custom tasks. Oh this many not works with the newest version of sshkit gem. I know it works with 1.7.1. I say this because the master branch has changed the SSHKit::Command methods that are available.
you need to load a custom rake task in Capistrano config:
check for new task in console
cap -T
Based on the
capistrano/rails
gem: https://github.com/capistrano/rails/blob/master/lib/capistrano/tasks/migrations.rakeTry
capistrano-rake
Without messing with custom capistrano tasks or going into much detail, all you need to do is simply install the gem and you can start executing rake tasks on remote servers like this:
You can create a corresponding capistrano task to run a specific rake task like that: