Class: Dash::Commands::Lock

Inherits:
Base
  • Object
show all
Defined in:
lib/dash/commands/lock.rb

Constant Summary collapse

SCOPES =

The deploy lock is scoped to service+destination, so two destinations can deploy at once. Server-scoped resources — above all the single kamal-proxy container a host runs for every destination on it — need a lock that every destination contends for, hence :server.

%i[ destination server ].freeze

Constants inherited from Base

Base::DOCKER_HEALTH_STATUS_FORMAT, Base::NO_HEALTHCHECK

Instance Attribute Summary collapse

Attributes inherited from Base

#config

Instance Method Summary collapse

Methods inherited from Base

#container_id_for, #ensure_docker_installed, #ensure_run_directory, #make_directory, #make_directory_for, #read_file, #remove_directory, #remove_file, #run_over_ssh

Constructor Details

#initialize(config, scope: :destination) ⇒ Lock

Returns a new instance of Lock.

Raises:

  • (ArgumentError)


14
15
16
17
18
19
# File 'lib/dash/commands/lock.rb', line 14

def initialize(config, scope: :destination)
  raise ArgumentError, "Unknown lock scope: #{scope}" unless SCOPES.include?(scope)

  super(config)
  @scope = scope
end

Instance Attribute Details

#scopeObject (readonly)

Returns the value of attribute scope.



12
13
14
# File 'lib/dash/commands/lock.rb', line 12

def scope
  @scope
end

Instance Method Details

#acquire(message, version) ⇒ Object



21
22
23
24
25
# File 'lib/dash/commands/lock.rb', line 21

def acquire(message, version)
  combine \
    [ :mkdir, lock_dir ],
    write_lock_details(message, version)
end

#ensure_locks_directoryObject



39
40
41
# File 'lib/dash/commands/lock.rb', line 39

def ensure_locks_directory
  [ :mkdir, "-p", locks_dir ]
end

#releaseObject



27
28
29
30
31
# File 'lib/dash/commands/lock.rb', line 27

def release
  combine \
    [ :rm, lock_details_file ],
    [ :rm, "-r", lock_dir ]
end

#statusObject



33
34
35
36
37
# File 'lib/dash/commands/lock.rb', line 33

def status
  combine \
    stat_lock_dir,
    read_lock_details
end