title: How to run custom rake task via capistrano 3?
body: <p>which way, i can run rake commands via capistrano on remote server.</p>
  
  <p>for example i have a <code>lib/task/reparse.rake</code> with some methods  </p>
  
  <pre><code>desc "it's take csv file, makes some changes and fill db with this info"
  task :example1 =&gt; :environment do
    require 'csv'
    rows_to_insert = []
    # some actions
    # ...
  end
  </code></pre>
  
  <p>on local server all is fine - i just run <code>rake reparse:example1</code>
  and it's work(fill db correctly).
  so question is - how can i run this command on real hosting, after deploy?</p>
  
  <p>i'am using rails 4.1 + capistrano 3.</p>
  
  <p>P.S. examples from site not work for me
  <a href="https://stackoverflow.com/questions/312214/how-do-i-run-a-rake-task-from-capistrano">How do I run a rake task from Capistrano?</a></p>
  
  <p>if i try <code>cap production rake:invoke task=reparse:land</code>
  it fails with:</p>
  
  <pre><code>cap aborted!
  Don't know how to build task 'rake:invoke'
  </code></pre>
  
  <hr>
  
  <p>some fixes</p>
  
  <pre><code>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
  </code></pre>
  
  <p>with such way it begin to execute via</p>
  
  <pre><code>cap production somenamespace:runrake task=custom_task_file:custom_method1
  </code></pre>