Class: PgQueue::Job

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Job

Returns a new instance of Job.



7
8
9
10
11
# File 'lib/pg_queue/job.rb', line 7

def initialize(attributes)
  @id = attributes["id"]
  @klass = Object.const_get(attributes["class_name"])
  @args = MultiJson.decode(attributes["args"])
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



5
6
7
# File 'lib/pg_queue/job.rb', line 5

def args
  @args
end

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/pg_queue/job.rb', line 5

def id
  @id
end

#klassObject (readonly)

Returns the value of attribute klass.



5
6
7
# File 'lib/pg_queue/job.rb', line 5

def klass
  @klass
end

Instance Method Details

#performObject



13
14
15
16
17
18
19
# File 'lib/pg_queue/job.rb', line 13

def perform
  PgQueue.logger.debug("performing job #{@id}")
  klass.perform(*args)
  PgQueue.logger.debug("job #{@id} performed")

  klass.after_perform(*args) if klass.respond_to?(:after_perform)
end