Module: Sidekiq::Status::Worker

Includes:
Storage
Defined in:
lib/sidekiq-status/worker.rb

Defined Under Namespace

Classes: Stopped

Constant Summary

Constants included from Storage

Storage::BATCH_LIMIT, Storage::RESERVED_FIELDS

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#expirationObject

Returns the value of attribute expiration.



7
8
9
# File 'lib/sidekiq-status/worker.rb', line 7

def expiration
  @expiration
end

Instance Method Details

#at(num, message = nil) ⇒ String

Sets current task progress (inspired by resque-status)

Parameters:

  • Fixnum

    number of tasks done

  • String

    optional message

Returns:

  • (String)


29
30
31
32
33
# File 'lib/sidekiq-status/worker.rb', line 29

def at(num, message = nil)
  @_status_total = 100 if @_status_total.nil?
  pct_complete = ((num / @_status_total.to_f) * 100).to_i rescue 0
  store(at: num, total: @_status_total, pct_complete: pct_complete, message: message, working_at: working_at)
end

#retrieve(name) ⇒ String

Read value from job status hash

Parameters:

  • String|Symbol

    hask key

Returns:

  • (String)


20
21
22
# File 'lib/sidekiq-status/worker.rb', line 20

def retrieve(name)
  read_field_for_id @provider_job_id || @job_id || @jid || "", name
end

#store(hash) ⇒ String

Stores multiple values into a job’s status hash, sets last update time

Parameters:

  • status_updates (Hash)

    updated values

Returns:

  • (String)

    Redis operation status code



13
14
15
# File 'lib/sidekiq-status/worker.rb', line 13

def store(hash)
  store_for_id @provider_job_id || @job_id || @jid || "", hash, @expiration
end

#total(num) ⇒ String

Sets total number of tasks

Parameters:

  • Fixnum

    total number of tasks

Returns:

  • (String)


38
39
40
41
# File 'lib/sidekiq-status/worker.rb', line 38

def total(num)
  @_status_total = num
  store(total: num, working_at: working_at)
end