Class: RemoteRun::Host::LockFile

Inherits:
Object
  • Object
show all
Defined in:
lib/remote_run/host.rb

Defined Under Namespace

Classes: RemoteFile

Constant Summary collapse

FILE =
"/tmp/remote-run-lock"

Instance Method Summary collapse

Constructor Details

#initialize(remote_hostname, local_hostname, unique_run_marker, configuration) ⇒ LockFile

Returns a new instance of LockFile.



71
72
73
74
75
# File 'lib/remote_run/host.rb', line 71

def initialize(remote_hostname, local_hostname, unique_run_marker, configuration)
  @filename = FILE
  @locker = "#{local_hostname}-#{unique_run_marker}"
  @remote_file = RemoteFile.new(remote_hostname, configuration)
end

Instance Method Details

#getObject



91
92
93
# File 'lib/remote_run/host.rb', line 91

def get
  @remote_file.write(@filename, @locker)
end

#locked?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/remote_run/host.rb', line 83

def locked?
  @remote_file.exist?(@filename)
end

#locked_by_me?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/remote_run/host.rb', line 87

def locked_by_me?
  @remote_file.exist?(@filename) && @remote_file.read(@filename).strip == @locker
end

#releaseObject



77
78
79
80
81
# File 'lib/remote_run/host.rb', line 77

def release
  if locked_by_me?
    @remote_file.delete(@filename)
  end
end