Class: Bellbro::Worker

Inherits:
Object
  • Object
show all
Extended by:
SidekiqUtils
Includes:
Hooks, Trackable, Shout, Sidekiq::Worker
Defined in:
lib/bellbro/worker.rb

Instance Attribute Summary collapse

Attributes included from Trackable

#record

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SidekiqUtils

_jobs, _workers, active_workers, clear_all_queues, job_domain, job_jid, jobs_for_class, jobs_for_queue, jobs_in_flight_with_domain, jobs_with_domain, number_of_active_workers, queued_jobs, queues, worker_class, worker_domain, worker_jid, worker_queue, worker_time, workers, workers_for_class, workers_for_queue, workers_with_domain

Methods included from Hooks

#abort!, #aborted?, included

Methods included from Trackable

included, #record_incr, #record_set, #status_update, #stop_tracking, #track, #tracking?, #write_log

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



9
10
11
# File 'lib/bellbro/worker.rb', line 9

def context
  @context
end

Class Method Details

.should_run?Boolean

Returns:

  • (Boolean)


37
38
39
40
# File 'lib/bellbro/worker.rb', line 37

def self.should_run?
  # override
  true
end

Instance Method Details

#callObject



25
26
27
# File 'lib/bellbro/worker.rb', line 25

def call
  # override
end

#debug?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/bellbro/worker.rb', line 33

def debug?
  @debug ||= !!context[:debug] rescue false
end

#perform(args) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/bellbro/worker.rb', line 13

def perform(args)
  return unless args.present?
  set_context(args)
  run_before_hooks
  return if aborted?
  call
  return if aborted?
  run_after_hooks
ensure
  run_always_hooks
end

#should_run?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/bellbro/worker.rb', line 29

def should_run?
  self.class.should_run? || abort!
end