Class: WebTaskRunner::TaskWorker

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Status::Worker, Sidekiq::Worker
Defined in:
lib/web_task_runner/task_worker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#paramsObject

Returns the value of attribute params.



12
13
14
# File 'lib/web_task_runner/task_worker.rb', line 12

def params
  @params
end

Instance Method Details

#execObject



37
38
39
40
41
# File 'lib/web_task_runner/task_worker.rb', line 37

def exec
  puts <<-EOF
    Define the work in #{self.class}#exec!
  EOF
end

#job_numberObject



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/web_task_runner/task_worker.rb', line 25

def job_number
  job_number = 0
  klass = self.class
  WebTaskRunner.jobs.each_with_index do |job, i|
    if job == klass
      job_number = i + 1
      break
    end
  end
  job_number
end

#perform(params = nil) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/web_task_runner/task_worker.rb', line 14

def perform(params = nil)
  return if WebTaskRunner.current_state == 'idle'

  self.params = HashWithIndifferentAccess[params]

  exec

  puts "Job ##{job_number} done."
  WebTaskRunner.job_ended
end