Class: Hako::Commander

Inherits:
Object
  • Object
show all
Defined in:
lib/hako/commander.rb

Defined Under Namespace

Classes: SignalTrapped

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Commander

Returns a new instance of Commander.



11
12
13
# File 'lib/hako/commander.rb', line 11

def initialize(app)
  @app = app
end

Instance Method Details

#deploy(force: false, tag: 'latest', dry_run: false) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/hako/commander.rb', line 15

def deploy(force: false, tag: 'latest', dry_run: false)
  containers = load_containers(tag, dry_run: dry_run)
  scripts = @app.yaml.fetch('scripts', []).map { |config| load_script(config, dry_run: dry_run) }
  volumes = @app.yaml.fetch('volumes', [])
  scheduler = load_scheduler(@app.yaml['scheduler'], scripts, volumes: volumes, force: force, dry_run: dry_run)

  scripts.each { |script| script.before_deploy(containers) }
  scheduler.deploy(containers)
  scripts.each { |script| script.after_deploy(containers) }
end

#oneshot(commands, tag:, containers:, env: {}, dry_run: false) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/hako/commander.rb', line 26

def oneshot(commands, tag:, containers:, env: {}, dry_run: false)
  containers = load_containers(tag, dry_run: dry_run, with: containers)
  scripts = @app.yaml.fetch('scripts', []).map { |config| load_script(config, dry_run: dry_run) }
  volumes = @app.yaml.fetch('volumes', [])
  scheduler = load_scheduler(@app.yaml['scheduler'], scripts, volumes: volumes, dry_run: dry_run)

  exit_code = with_oneshot_signal_handlers(scheduler) do
    scheduler.oneshot(containers, commands, env)
  end
  exit exit_code
end

#removeObject



42
43
44
45
46
# File 'lib/hako/commander.rb', line 42

def remove
  scripts = @app.yaml.fetch('scripts', []).map { |config| load_script(config, dry_run: dry_run) }
  load_scheduler(@app.yaml['scheduler'], scripts).remove
  scripts.each(&:after_remove)
end

#statusObject



38
39
40
# File 'lib/hako/commander.rb', line 38

def status
  load_scheduler(@app.yaml['scheduler'], []).status
end