Performing a rake task on a remote server

The physical architecture of the production environment includes several machines that perform different tasks (rake tasks), all of them on the same database.

One of the tasks will do a large UPDATE on the table, which usually returns a postgres stub if other tasks are performed.

I already have a rake task to gracefully stop other tasks, but I can only do it from local machines.

What I want to achieve:

 task :big_update => :environment do stop_tasks_on_another_servers # do the SQL UPDATE ... end 

where stop_tasks_on_another_servers should do the rake task on other servers.

My best attempt was to use the gem https://github.com/capistrano/sshkit . It’s the same as Capistrano, but I still don’t see a step here. I am trying to do the following on the rails console in a production machine:

 require 'sshkit/dsl' hosts = ['machine1', 'machine2'] on hosts do within "/home/me/project/current" do with rails_env: :production do rake "stop_tasks" end end end 

But it returns:

 INFO [70a0610a] Running /usr/bin/env rake stop_tasks on machine1 SSHKit::Command::Failed: rake stdout: Nothing written 

What am I missing or is there an easier way to do remote tasks?

+7
ruby ruby-on-rails rake
source share
2 answers

Check out the Rake Remote Task . Here is a snippet showing how it works:

 require 'rake/remote_task' set :domain, 'abc.example.com' remote_task :foo do run "ls" end 
+3
source share
0
source share

All Articles