Module: Sidekiq::Hierarchy

Defined in:
lib/sidekiq/hierarchy.rb,
lib/sidekiq/hierarchy/job.rb,
lib/sidekiq/hierarchy/web.rb,
lib/sidekiq/hierarchy/http.rb,
lib/sidekiq/hierarchy/version.rb,
lib/sidekiq/hierarchy/workflow.rb,
lib/sidekiq/hierarchy/observers.rb,
lib/sidekiq/hierarchy/web/helpers.rb,
lib/sidekiq/hierarchy/workflow_set.rb,
lib/sidekiq/hierarchy/notifications.rb,
lib/sidekiq/hierarchy/rack/middleware.rb,
lib/sidekiq/hierarchy/redis_connection.rb,
lib/sidekiq/hierarchy/callback_registry.rb,
lib/sidekiq/hierarchy/client/middleware.rb,
lib/sidekiq/hierarchy/server/middleware.rb,
lib/sidekiq/hierarchy/faraday/middleware.rb,
lib/sidekiq/hierarchy/observers/job_update.rb,
lib/sidekiq/hierarchy/observers/workflow_update.rb

Defined Under Namespace

Modules: Client, Faraday, Http, Notifications, Observers, Rack, RedisConnection, Server, Web Classes: CallbackRegistry, CompleteSet, FailedSet, Job, PruningSet, RunningSet, Workflow, WorkflowSet

Constant Summary collapse

VERSION =
'2.0.1'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.callback_registryObject

Callbacks



97
98
99
# File 'lib/sidekiq/hierarchy.rb', line 97

def callback_registry
  @callback_registry
end

Class Method Details

.current_jobObject

Retrieves job for the current Sidekiq job if previously set



51
52
53
# File 'lib/sidekiq/hierarchy.rb', line 51

def current_job
  Thread.current[:sidekiq_hierarchy_job]
end

.current_job=(job) ⇒ Object

Sets the job for the current fiber/worker



46
47
48
# File 'lib/sidekiq/hierarchy.rb', line 46

def current_job=(job)
  Thread.current[:sidekiq_hierarchy_job] = job
end

.current_workflowObject

Retrieves the current Sidekiq workflow if previously set



41
42
43
# File 'lib/sidekiq/hierarchy.rb', line 41

def current_workflow
  Thread.current[:sidekiq_hierarchy_workflow]
end

.current_workflow=(workflow) ⇒ Object

Sets the workflow object for the current fiber/worker



36
37
38
# File 'lib/sidekiq/hierarchy.rb', line 36

def current_workflow=(workflow)
  Thread.current[:sidekiq_hierarchy_workflow] = workflow
end

.enabled?Boolean

Checks if tracking is enabled based on whether the workflow is known If disabled, all methods are no-ops

Returns:

  • (Boolean)


31
32
33
# File 'lib/sidekiq/hierarchy.rb', line 31

def enabled?
  !!current_workflow  # without a workflow, we can't do anything
end

.publish(event, *args) ⇒ Object



103
104
105
# File 'lib/sidekiq/hierarchy.rb', line 103

def publish(event, *args)
  callback_registry.publish(event, *args)
end

.record_job_completeObject



79
80
81
82
# File 'lib/sidekiq/hierarchy.rb', line 79

def record_job_complete
  return unless enabled? && current_job
  current_job.complete!
end

.record_job_enqueued(job) ⇒ Object

Workflow execution updates



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/sidekiq/hierarchy.rb', line 58

def record_job_enqueued(job)
  return unless !!job['workflow']
  if current_job.nil?
    # this is a root-level job, i.e., start of a workflow
    queued_job = Job.create(job['jid'], job)
    queued_job.enqueue!  # initial status: enqueued
  elsif current_job.jid == job['jid']
    # this is a job requeuing itself, ignore it
  else
    # this is an intermediate job, having both parent and children
    queued_job = Job.create(job['jid'], job)
    current_job.add_child(queued_job)
    queued_job.enqueue!  # initial status: enqueued
  end
end

.record_job_failedObject



89
90
91
92
# File 'lib/sidekiq/hierarchy.rb', line 89

def record_job_failed
  return unless enabled? && current_job
  current_job.fail!
end

.record_job_requeuedObject



84
85
86
87
# File 'lib/sidekiq/hierarchy.rb', line 84

def record_job_requeued
  return unless enabled? && current_job
  current_job.requeue!
end

.record_job_runningObject



74
75
76
77
# File 'lib/sidekiq/hierarchy.rb', line 74

def record_job_running
  return unless enabled? && current_job
  current_job.run!
end

.redis=(conn) ⇒ Object

Global redis store – overrides default Sidekiq redis



23
24
25
# File 'lib/sidekiq/hierarchy.rb', line 23

def redis=(conn)
  RedisConnection.redis = conn
end

.subscribe(event, callback) ⇒ Object



99
100
101
# File 'lib/sidekiq/hierarchy.rb', line 99

def subscribe(event, callback)
  callback_registry.subscribe(event, callback)
end