Class: Taskinator::JobWorker

Inherits:
Object
  • Object
show all
Defined in:
lib/taskinator/job_worker.rb

Instance Method Summary collapse

Constructor Details

#initialize(uuid) ⇒ JobWorker

Returns a new instance of JobWorker.



3
4
5
# File 'lib/taskinator/job_worker.rb', line 3

def initialize(uuid)
  @uuid = uuid
end

Instance Method Details

#perform(&block) ⇒ Object

NB: must be provided a block for the implmentation of the job execution



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/taskinator/job_worker.rb', line 8

def perform(&block)
  task = Taskinator::Task.fetch(@uuid)
  return if task.paused? || task.cancelled?
  begin
    task.start!
    task.perform &block
    task.complete!
  rescue Exception => e
    Taskinator.logger.error(e)
    task.fail!(e)
    raise e
  end
end