Module: RocketJob::Batch::Model
- Extended by:
- ActiveSupport::Concern
- Included in:
- RocketJob::Batch
- Defined in:
- lib/rocket_job/batch/model.rb
Overview
Model attributes
Instance Method Summary collapse
-
#percent_complete ⇒ Object
Returns [Integer] percent of records completed so far Returns 0 if the total record count has not yet been set.
-
#status(time_zone = 'Eastern Time (US & Canada)') ⇒ Object
Returns [Hash] status of this job.
-
#worker_count ⇒ Object
Returns [Integer] the number of workers currently working on this job.
-
#worker_names ⇒ Object
Returns [Array<String>] names of workers currently working this job.
Instance Method Details
#percent_complete ⇒ Object
Returns [Integer] percent of records completed so far Returns 0 if the total record count has not yet been set
78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/rocket_job/batch/model.rb', line 78 def percent_complete return 100 if completed? return 0 unless record_count.to_i > 0 # Approximate number of input records input_records = input.count.to_f * slice_size if input_records > record_count # Sanity check in case slice_size is not being adhered to 99 else ((1.0 - (input_records.to_f / record_count)) * 100).to_i end end |
#status(time_zone = 'Eastern Time (US & Canada)') ⇒ Object
Returns [Hash] status of this job
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/rocket_job/batch/model.rb', line 93 def status(time_zone = 'Eastern Time (US & Canada)') h = {} case when queued? h['queued_slices'] = input.queued.count when running? || paused? || failed? h['active_slices'] = worker_count h['failed_slices'] = input.failed.count h['queued_slices'] = input.queued.count # Very high level estimated time left if record_count && running? && (record_count > 0) percent = percent_complete if percent >= 5 secs = seconds.to_f h['est_remaining_duration'] = RocketJob.seconds_as_duration((((secs / percent) * 100) - secs)) end end when completed? secs = seconds.to_f h['records_per_hour'] = ((record_count.to_f / secs) * 60 * 60).round if record_count && (record_count > 0) && (secs > 0.0) end h['output_slices'] = output.count if collect_output? && !completed? h.merge!(super(time_zone)) h.delete('result') # Worker name should be retrieved from the slices when processing h.delete('worker_name') if sub_state == :processing h end |
#worker_count ⇒ Object
Returns [Integer] the number of workers currently working on this job.
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/rocket_job/batch/model.rb', line 137 def worker_count return 0 unless running? # Cache the number of workers for 1 second. return @worker_count if @worker_count_last && (@worker_count_last == Time.now.to_i) @worker_count = case sub_state when :before, :after 1 when :processing input.running.count else 0 end @worker_count_last = Time.now.to_i @worker_count end |
#worker_names ⇒ Object
Returns [Array<String>] names of workers currently working this job.
123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/rocket_job/batch/model.rb', line 123 def worker_names return [] unless running? case sub_state when :before, :after worker_name when :processing input.running.collect { |slice| slice.worker_name } else [] end end |