Class: RemoteRun::Host::LockFile
- Inherits:
-
Object
- Object
- RemoteRun::Host::LockFile
- Defined in:
- lib/remote_run/host.rb
Defined Under Namespace
Classes: RemoteFile
Constant Summary collapse
- FILE =
"/tmp/remote-run-lock"
Instance Method Summary collapse
- #get ⇒ Object
-
#initialize(remote_hostname, local_hostname, unique_run_marker, configuration) ⇒ LockFile
constructor
A new instance of LockFile.
- #locked? ⇒ Boolean
- #locked_by_me? ⇒ Boolean
- #release ⇒ Object
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
#get ⇒ Object
91 92 93 |
# File 'lib/remote_run/host.rb', line 91 def get @remote_file.write(@filename, @locker) end |
#locked? ⇒ Boolean
83 84 85 |
# File 'lib/remote_run/host.rb', line 83 def locked? @remote_file.exist?(@filename) end |
#locked_by_me? ⇒ 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 |
#release ⇒ Object
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 |