Class: EQ::Job

Inherits:
Object
  • Object
show all
Defined in:
lib/eq/job.rb

Defined Under Namespace

Classes: UnknownJobClassError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, queue, payload = nil) ⇒ Job

Returns a new instance of Job.



6
7
8
9
10
# File 'lib/eq/job.rb', line 6

def initialize id, queue, payload=nil
  @id = id
  @queue = queue.to_s
  @payload = payload
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/eq/job.rb', line 4

def id
  @id
end

#payloadObject (readonly)

Returns the value of attribute payload.



4
5
6
# File 'lib/eq/job.rb', line 4

def payload
  @payload
end

#queueObject (readonly)

Returns the value of attribute queue.



4
5
6
# File 'lib/eq/job.rb', line 4

def queue
  @queue
end

Instance Method Details

#config(name) ⇒ Object



27
28
29
# File 'lib/eq/job.rb', line 27

def config name
  job_class.instance_variable_get "@#{name}"
end

#job_classObject



17
18
19
20
21
# File 'lib/eq/job.rb', line 17

def job_class
  queue.split("::").inject(Kernel){|constant,part| constant.const_get(part)}
rescue NameError => e
  raise UnknownJobClassError, e.to_s
end

#performObject

calls MyJobClass.perform(*payload)



13
14
15
# File 'lib/eq/job.rb', line 13

def perform
  job_class.perform *payload
end

#unique?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/eq/job.rb', line 23

def unique?
  config(:unique) == true
end