class Cloudtasker::Batch::BatchProgress
Capture the progress of a batch
Attributes
Public Class Methods
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
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
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
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
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
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
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
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
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
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
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 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