class Cloudtasker::Batch::BatchProgress

Capture the progress of a batch

Attributes

batch_state[R]

Public Class Methods

new(batch_state = {}) click to toggle source

Build a new instance of the class.

@param [Hash] batch_state The batch state

# File lib/cloudtasker/batch/batch_progress.rb, line 16
def initialize(batch_state = {})
  @batch_state = batch_state
end

Public Instance Methods

+(other) click to toggle source

Add a batch progress to another one.

@param [Cloudtasker::Batch::BatchProgress] progress The progress to add.

@return [Cloudtasker::Batch::BatchProgress] The sum of the two batch progresses.

# File lib/cloudtasker/batch/batch_progress.rb, line 110
def +(other)
  self.class.new(batch_state.to_h.merge(other.batch_state.to_h))
end
completed() click to toggle source

Return the number of completed jobs.

@return [Integer] The number of completed jobs.

# File lib/cloudtasker/batch/batch_progress.rb, line 34
def completed
  @completed ||= count('completed')
end
dead() click to toggle source

Return the number of dead jobs.

@return [Integer] The number of dead jobs.

# File lib/cloudtasker/batch/batch_progress.rb, line 70
def dead
  @dead ||= count('dead')
end
done() click to toggle source

Return the number of jobs completed or dead.

@return [Integer] The number of jobs done.

# File lib/cloudtasker/batch/batch_progress.rb, line 88
def done
  completed + dead
end
errored() click to toggle source

Return the number of jobs with errors.

@return [Integer] The number of errored jobs.

# File lib/cloudtasker/batch/batch_progress.rb, line 61
def errored
  @errored ||= count('errored')
end
pending() click to toggle source

Return the number of jobs not completed yet.

@return [Integer] The number of jobs pending.

# File lib/cloudtasker/batch/batch_progress.rb, line 79
def pending
  total - done
end
percent() click to toggle source

Return the batch progress percentage.

@return [Float] The progress percentage.

# File lib/cloudtasker/batch/batch_progress.rb, line 97
def percent
  return 0 if total.zero?

  (done.to_f / total) * 100
end
processing() click to toggle source

Return the number of processing jobs.

@return [Integer] The number of processing jobs.

# File lib/cloudtasker/batch/batch_progress.rb, line 52
def processing
  @processing ||= count('processing')
end
scheduled() click to toggle source

Return the number of scheduled jobs.

@return [Integer] The number of scheduled jobs.

# File lib/cloudtasker/batch/batch_progress.rb, line 43
def scheduled
  @scheduled ||= count('scheduled')
end
total() click to toggle source

Return the total number jobs.

@return [Integer] The number number of jobs.

# File lib/cloudtasker/batch/batch_progress.rb, line 25
def total
  count
end

Private Instance Methods

count(status = nil) click to toggle source

Count the number of items in a given status

# File lib/cloudtasker/batch/batch_progress.rb, line 117
def count(status = nil)
  return batch_state.to_h.keys.size unless status

  batch_state.to_h.values.count { |e| e == status }
end