Module: Workers::StatusBroadcastable::Overrides

Included in:
Workers::StatusBroadcastable
Defined in:
app/concerns/workers/status_broadcastable.rb

Overview

Overrides for at/total/store that must be PREPENDED so they sit above
Sidekiq::Status::Worker in the MRO (StatusBroadcastable itself is included
after Sidekiq::Status::Worker, so plain instance methods on it would lose
the method-lookup race).

Instance Method Summary collapse

Instance Method Details

#at(step, message = nil) ⇒ Object

Records the current step and fires a live progress broadcast.

Parameters:

  • step (Integer)

    the step number reached

  • message (String, nil) (defaults to: nil)

    optional progress message

Returns:

  • (Object)

    the result of Sidekiq::Status::Worker#at



43
44
45
46
47
# File 'app/concerns/workers/status_broadcastable.rb', line 43

def at(step, message = nil)
  result = super
  broadcast_job_status if broadcast_enabled?
  result
end

#store(hash = {}) ⇒ Object

Called when job completes or stores flash messages (redirect_to, etc.)

Parameters:

  • hash (Hash{Symbol, String => Object}) (defaults to: {})

    values to persist in the job status

Returns:

  • (Object)

    the result of Sidekiq::Status::Worker#store



63
64
65
66
67
68
69
70
71
# File 'app/concerns/workers/status_broadcastable.rb', line 63

def store(hash = {})
  result = super
  if hash.keys.any? { |k| terminal_status_key?(k) }
    broadcast_job_status(terminal: true)
  elsif broadcast_enabled?
    broadcast_job_status
  end
  result
end

#total(total_steps = nil) ⇒ Object

Sets the total number of steps and fires a live progress broadcast.

Parameters:

  • total_steps (Integer, nil) (defaults to: nil)

    the total number of steps for the job

Returns:

  • (Object)

    the result of Sidekiq::Status::Worker#total



53
54
55
56
57
# File 'app/concerns/workers/status_broadcastable.rb', line 53

def total(total_steps = nil)
  result = super
  broadcast_job_status if broadcast_enabled?
  result
end