Class: Epi::JobDescription

Inherits:
Object
  • Object
show all
Defined in:
lib/epi/job_description.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id) ⇒ JobDescription

Returns a new instance of JobDescription.



61
62
63
64
65
# File 'lib/epi/job_description.rb', line 61

def initialize(id)
  @id = id
  @triggers = []
  @props = {}
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



59
60
61
# File 'lib/epi/job_description.rb', line 59

def id
  @id
end

#triggersObject (readonly)

Returns the value of attribute triggers.



59
60
61
# File 'lib/epi/job_description.rb', line 59

def triggers
  @triggers
end

Class Method Details

.property(method, default = nil, &validator) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/epi/job_description.rb', line 7

def self.property(method, default = nil, &validator)
  define_method method do
    @props.key?(method) ? @props[method] : default
  end
  define_method :"#{method}=" do |value|
    if validator
      result = validator.call(value)
      raise Exceptions::Fatal, "Invalid value '#{value}' of type #{value.class.name} for #{method}: #{result}" if result
    end
    @props[method] = value
  end
end

Instance Method Details

#launchObject



67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/epi/job_description.rb', line 67

def launch
  proc_id = generate_id
  opts = {
      cwd: directory,
      user: user,
      env: environment || {},
      stdout: stdout,
      stderr: stderr
  }
  pid = Epi.launch command, **opts
  [proc_id, pid]
end

#on(trigger_name, *args, &handler) ⇒ Object



86
87
88
# File 'lib/epi/job_description.rb', line 86

def on(trigger_name, *args, &handler)
  @triggers << [trigger_name, args, handler]
end

#reconfigure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



80
81
82
83
84
# File 'lib/epi/job_description.rb', line 80

def reconfigure
  @triggers = []
  yield self
  # TODO: trigger an update of existing/running jobs
end