Class: Nocode::JobExecutor

Inherits:
Object
  • Object
show all
Defined in:
lib/nocode/job_executor.rb

Overview

Manages the lifecycle and executes a job.

Constant Summary collapse

PARAMETERS_KEY =
'parameters'
REGISTERS_KEY =
'registers'
STEPS_KEY =
'steps'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(yaml, io: $stdout) ⇒ JobExecutor

Returns a new instance of JobExecutor.



15
16
17
18
19
20
21
# File 'lib/nocode/job_executor.rb', line 15

def initialize(yaml, io: $stdout)
  @yaml = yaml.respond_to?(:read) ? yaml.read : yaml
  @yaml = YAML.safe_load(@yaml) || {}
  @io   = io

  freeze
end

Instance Attribute Details

#ioObject (readonly)

Returns the value of attribute io.



13
14
15
# File 'lib/nocode/job_executor.rb', line 13

def io
  @io
end

#yamlObject (readonly)

Returns the value of attribute yaml.



13
14
15
# File 'lib/nocode/job_executor.rb', line 13

def yaml
  @yaml
end

Instance Method Details

#executeObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/nocode/job_executor.rb', line 23

def execute
  steps      = yaml[STEPS_KEY] || []
  parameters = yaml[PARAMETERS_KEY] || {}
  registers  = yaml[REGISTERS_KEY] || {}

  context = Context.new(
    io: io,
    parameters: parameters,
    registers: registers
  )

  log_title(context)

  StepsExecutor.new(context: context, steps: steps).execute

  context.log("Ended: #{DateTime.now}")
  context.log_line

  context
end