Class: Seijaku::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/seijaku/task.rb

Overview

Task is composed of a name, an array of Step (Pre, Post)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(task, variables, logger, ssh_hosts = nil, ssh_settings = {}) ⇒ Task

Returns a new instance of Task.

Raises:



8
9
10
11
12
13
14
15
16
17
# File 'lib/seijaku/task.rb', line 8

def initialize(task, variables, logger, ssh_hosts = nil, ssh_settings = {})
  @name = task.fetch(:name, nil)
  @host = task.fetch(:host, nil)
  @steps = task.fetch(:steps, []).map { |step| Step.new(step, variables, :steps, logger, self, ssh_hosts, ssh_settings) }
  @pre_steps = task.fetch(:pre, []).map { |step| Step.new(step, variables, :pre, logger, self, ssh_hosts, ssh_settings) }
  @post_steps = task.fetch(:post, []).map { |step| Step.new(step, variables, :post, logger, self, ssh_hosts, ssh_settings) }
  @logger = logger

  raise TaskError, "no name set in task", [] if @name.nil?
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



6
7
8
# File 'lib/seijaku/task.rb', line 6

def host
  @host
end

Instance Method Details

#execute!Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/seijaku/task.rb', line 19

def execute!
  [@pre_steps, @steps, @post_steps].each do |pipeline_steps|
    pipeline_steps.each do |step|
      @logger.info(format("[%<name>s:%<pipeline>s] running %<command>s",
                          name: @name,
                          pipeline: step.pipeline,
                          command: step.command))

      step.execute!
    end
  end
end