class Epi::JobDescription

Attributes

id[R]
triggers[R]

Public Class Methods

new(id) click to toggle source
# File lib/epi/job_description.rb, line 61
def initialize(id)
  @id = id
  @triggers = []
  @props = {}
end
property(method, default = nil, &validator) click to toggle source
# 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

Public Instance Methods

launch() click to toggle source
# 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) click to toggle source
# File lib/epi/job_description.rb, line 86
def on(trigger_name, *args, &handler)
  @triggers << [trigger_name, args, handler]
end
reconfigure() { |self| ... } click to toggle source
# File lib/epi/job_description.rb, line 80
def reconfigure
  @triggers = []
  yield self
  # TODO: trigger an update of existing/running jobs
end

Private Instance Methods

generate_id() click to toggle source
# File lib/epi/job_description.rb, line 92
def generate_id
  SecureRandom.hex 4
end