Class: ActiveQueue::Job

Inherits:
Object
  • Object
show all
Extended by:
ClassMethods
Defined in:
lib/active_queue/job.rb

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Job

Returns a new instance of Job.



18
19
20
21
22
23
24
25
26
27
# File 'lib/active_queue/job.rb', line 18

def initialize(options)
  @options = options
  @val = options[:val] || options["val"]
  @job_klass = options[:job_klass] || options["job_klass"]
  @queue = options[:queue_name] ? options[:queue_name].to_sym : :file_queue
  @queue_adapter = options[:adapter] ? options[:adapter] : Adapter::DefaultAdapter.new
  if @queue_adapter.class == String
    @queue_adapter = adapters[@queue_adapter] ? adapters[@queue_adapter].new : nil
  end
end

Instance Attribute Details

#job_klassObject

Returns the value of attribute job_klass.



17
18
19
# File 'lib/active_queue/job.rb', line 17

def job_klass
  @job_klass
end

#optionsObject

Returns the value of attribute options.



17
18
19
# File 'lib/active_queue/job.rb', line 17

def options
  @options
end

#perform_actionObject

Returns the value of attribute perform_action.



17
18
19
# File 'lib/active_queue/job.rb', line 17

def perform_action
  @perform_action
end

#queueObject

Returns the value of attribute queue.



17
18
19
# File 'lib/active_queue/job.rb', line 17

def queue
  @queue
end

#queue_adapterObject

Returns the value of attribute queue_adapter.



17
18
19
# File 'lib/active_queue/job.rb', line 17

def queue_adapter
  @queue_adapter
end

#queue_nameObject

Returns the value of attribute queue_name.



17
18
19
# File 'lib/active_queue/job.rb', line 17

def queue_name
  @queue_name
end

#valObject

Returns the value of attribute val.



17
18
19
# File 'lib/active_queue/job.rb', line 17

def val
  @val
end

Instance Method Details

#adaptersObject

def self.perform(value)

  #@value ||= options[:value] 
  value.preform
  #success = true
  #begin
  #@options[:value].perform
  #rescue Exception => e
  #  success = e.message
  #end
  #success
end
def enqueue
  @queue_adapter.enqueue(ActiveQueue::Job, @value)
end


52
53
54
55
56
# File 'lib/active_queue/job.rb', line 52

def adapters
  { "resque" => ActiveQueue::Adapter::ResqueAdapter, 
   "delayed" => ActiveQueue::Adapter::DelayedJobAdapter, 
   "insta" => ActiveQueue::Adapter::DefaultAdapter }
end

#enqueueObject



33
34
35
# File 'lib/active_queue/job.rb', line 33

def enqueue
  @queue_adapter.enqueue(self.class, :val => @val, :job_klass => @job_klass)
end

#perform(opt = nil) ⇒ Object



28
29
30
31
32
# File 'lib/active_queue/job.rb', line 28

def perform(opt = nil)
  #puts "lperf #{opt[:val].respond_to?('perform')}"
  opt ||= self.options
  ActiveQueue::Job.perform(opt)
end