Class: SimpleWorker::SshWorker

Inherits:
AbstractListener show all
Defined in:
lib/simpleworker/ssh_worker.rb

Overview

SshWorker.new(opts)

where ‘opts’ is a Hash of options:

:user    => String name of user on remote host (default: `whoami`)
:host    => String name of remote host (default: `hostname`)
:port    => String port to connect on the remote host (default: 22)
:cmd     => String bash string to execute on the remote host in the users login shell, in the remote 'dirname', and with the JOBID environment variable set to the current jobid, (default: `bundle install; rake;`)
:dirname => String remote directory in the users home directory (default: dynamic jobid)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractListener

#on_interrupted, #on_log, #on_node_start, #on_node_stop, #on_task_active, #on_task_expire, #on_task_start, #on_task_stop, #on_timeout, #update

Constructor Details

#initialize(opts = {}) ⇒ SshWorker

Returns a new instance of SshWorker.



18
19
20
21
22
23
24
# File 'lib/simpleworker/ssh_worker.rb', line 18

def initialize(opts = {})
  @user    = opts[:user] || `whoami`.strip
  @host    = opts[:host] || `hostname`.strip
  @port    = opts[:port] || '22'
  @cmd     = opts[:cmd]  || 'bundle install; rake;'
  @dirname = opts[:dirname]
end

Instance Attribute Details

#cmdObject (readonly)

Returns the value of attribute cmd.



16
17
18
# File 'lib/simpleworker/ssh_worker.rb', line 16

def cmd
  @cmd
end

#dirnameObject (readonly)

Returns the value of attribute dirname.



16
17
18
# File 'lib/simpleworker/ssh_worker.rb', line 16

def dirname
  @dirname
end

#hostObject (readonly)

Returns the value of attribute host.



16
17
18
# File 'lib/simpleworker/ssh_worker.rb', line 16

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



16
17
18
# File 'lib/simpleworker/ssh_worker.rb', line 16

def port
  @port
end

#userObject (readonly)

Returns the value of attribute user.



16
17
18
# File 'lib/simpleworker/ssh_worker.rb', line 16

def user
  @user
end

Instance Method Details

#on_start(jobid) ⇒ Object

Destructive rsync to remote and start a process in the background on the remote server.



27
28
29
30
31
32
33
# File 'lib/simpleworker/ssh_worker.rb', line 27

def on_start(jobid)
  @dirname ||= jobid
  @jobid = jobid

  sync_to_remote
  async_cmd
end

#on_stopObject

Rsync from remote.



36
37
38
# File 'lib/simpleworker/ssh_worker.rb', line 36

def on_stop
  sync_from_remote
end