class Rex::Job

This class is the concrete representation of an abstract job.

Attributes

ctx[R]

Some job context.

jid[R]

The job identifier as assigned by the job container.

name[R]

The name of the job.

start_time[R]

The time at which this job was started.

Public Class Methods

new(container, jid, name, ctx, run_proc, clean_proc) click to toggle source

Creates an individual job instance and initializes it with the supplied parameters.

# File lib/rex/job_container.rb, line 14
def initialize(container, jid, name, ctx, run_proc, clean_proc)
  self.container  = container
  self.jid        = jid
  self.name       = name
  self.run_proc   = run_proc
  self.clean_proc = clean_proc
  self.ctx        = ctx
  self.start_time = nil
end

Public Instance Methods

start(async = false) click to toggle source

Runs the job in the context of its own thread if the async flag is false. Otherwise, the job is run inline.

# File lib/rex/job_container.rb, line 28
def start(async = false)
  self.start_time = Time.now
  if (async)
    self.job_thread = Rex::ThreadFactory.spawn("JobID(#{jid})-#{name}", false) {
      # Deschedule our thread momentarily
      ::IO.select(nil, nil, nil, 0.01)

      begin
        run_proc.call(ctx)
      ensure
        clean_proc.call(ctx)
        container.remove_job(self)
      end
    }
  else
    begin
      run_proc.call(ctx)
    rescue ::Exception
      container.stop_job(jid)
      raise $!
    end
  end
end
stop() click to toggle source

Stops the job if it’s currently running and calls its cleanup procedure

# File lib/rex/job_container.rb, line 55
def stop
  if (self.job_thread)
    self.job_thread.kill
    self.job_thread = nil
  end

  clean_proc.call(ctx) if (clean_proc)
end