class Utils::ProcessJob

mechanisms for serialization and display of job information.
It holds command arguments, manages execution status, and provides
single executable task that can be enqueued and processed by a ProbeServer.
This class encapsulates the information and behavior associated with a
A process job representation for execution within the probe server system.

def as_json(*)

Returns:
  • (Hash) - a hash containing the type, id, and args of the process job
def as_json(*)
  { type:, id:, args:, }
end

def initialize(args:, probe_server: nil)

Returns:
  • (Utils::ProcessJob) - a new ProcessJob instance configured with

Parameters:
  • probe_server (Utils::ProbeServer, nil) -- the probe server instance
  • args (Array) -- the command arguments to be executed by the job
def initialize(args:, probe_server: nil)
  @id   = probe_server&.next_job_id
  @args = Array(args)
end

def inspect

Returns:
  • (String) - a formatted string representation of the process job
def inspect
  ok_colorize("#{id} #{args.map { |a| a.include?(' ') ? a.inspect : a } * ' '}")
end

def ok

Returns:
  • (String) - 'y' if the job succeeded, 'n' if it failed, or '…' if
def ok
  case @ok
  when false then 'n'
  when true  then 'y'
  else            '…'
  end
end

def ok_colorize(string)

Returns:
  • (String) - the colorized string or the original string if status is unknown

Parameters:
  • string (String) -- the string to be colorized
def ok_colorize(string)
  case @ok
  when false then white { on_red { string } }
  when true  then black { on_green { string } }
  else            string
  end
end

def to_json(*)

Returns:
  • (String) - a JSON string representation of the object
def to_json(*)
  as_json.to_json(*)
end

def type

Returns:
  • (String) - the string 'process_job' indicating the object's type
def type
  'process_job'
end