class Rasteira::Core::Job

Job class that is executed by rasteira.

Constants

STATUSES

Attributes

args[R]
status[R]
worker_class[R]
worker_file_path[R]

Public Class Methods

new(worker_class, options = {}) click to toggle source

The constructor of Rasteira::Core::Job @param [String, Class] worker_class The name or class of worker class or @param [Hash] options @option options [String] :worker_file_path The file path of worker_class.

If worker_file_path is set, Rasteira tries to load worker_class from worker_file_path

@option options [String] :current_directory The root path of worker_file_path.

If current_directory and worker_file_path are set, Rasteira searches worker_file_path
with current_directory as current directory.
# File lib/rasteira/core/job.rb, line 24
def initialize(worker_class, options = {})
  unless options[:worker_file_path].nil?
    @worker_file_path = File.expand_path(options[:worker_file_path], options[:current_directory] || Dir.pwd)
    unless File.exist?(@worker_file_path)
      raise ArgumentError, "#{@worker_file_path} could not be found"
    end

    require(@worker_file_path)
  end

  @worker_class = worker_class
  @args = options[:args]
  @status = STATUSES[:ready]
end

Public Instance Methods

start!() click to toggle source
# File lib/rasteira/core/job.rb, line 39
def start!
  @status = STATUSES[:in_process]
  begin
    worker.method(:perform).arity > 1 ? worker.perform(*@args) : worker.perform(@args)
    @status = STATUSES[:finished]
  rescue => e
    @status = STATUSES[:failed]
    raise e
  end
end
worker() click to toggle source
# File lib/rasteira/core/job.rb, line 50
def worker
  @worker ||= if @worker_class.is_a?(String)
                Object.const_get("::#{@worker_class}").new
              else
                @worker_class.new
              end
end