rocketjob 5.2.0.beta2 → 5.2.0.beta3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: be987bf17c7505ce19a06f0f15bd612b0d9588a7aed842250b4f094b98b026ef
4
- data.tar.gz: afb3b94b5f47c4fd462da9732f6b94d87b53f96e9afe22f66592c89eeed3c521
3
+ metadata.gz: 0cece68774d1d549fb219daa5f78f3def0e5b3c51d0659fea8812da200b6b268
4
+ data.tar.gz: 69ca23691dcbe2c8ba1b7b5a60a4d18cb8b033cf37510c2a0f1f0a02075357a7
5
5
  SHA512:
6
- metadata.gz: 0f71a2a1aa604c1db1babf43ea5865724617515b7f0ea299e438d8fb4bb845d2a4ef21c4bbd5994034cb070c72c6b6f53dfbf45d2b52e576c8a2cb3202e1549a
7
- data.tar.gz: 969bcffcb4aa38277b99f88188334e28393ed6fa92e5e470214879ec2d169e81a586947daaf3bcaea446ac8766e49e9c7dd328a4131bde0275808eff241a9437
6
+ metadata.gz: ff6d1c42eca584b91dbf27312b962ed4615168616a77531d70ca9a252145aac47f1c0a08655433aa956b143bab6a517e0b973b63474ba25cb718eb018df3950d
7
+ data.tar.gz: 9add07cf69e3bf6cfc0d1aa62902ce00deb07ba41f922491afbe531e00b364fddee70f99f86497b7ec45e97637e715d355e55a6c30dbebcde2a8811b907e4d03
@@ -63,7 +63,7 @@ module RocketJob
63
63
 
64
64
  # Cannot use this class since it will include instances of parent job classes.
65
65
  RocketJob::Job.with(read: {mode: :primary}) do |conn|
66
- conn.running.where("_type" => self.class.name, :id.ne => id, :priority.lt => priority).count >= throttle_running_jobs
66
+ conn.running.where("_type" => self.class.name, :id.ne => id, :priority.lte => priority).count >= throttle_running_jobs
67
67
  end
68
68
  end
69
69
  end
@@ -130,45 +130,56 @@ module RocketJob
130
130
  # Once the slice has been successfully processed it will be removed from the input collection
131
131
  # Returns [Integer] the number of records successfully processed
132
132
  def rocket_job_process_slice(slice, &block)
133
- # TODO: Skip records already processed
134
- @rocket_job_record_number = slice.first_record_number || 0
135
- @rocket_job_slice = slice
133
+ @rocket_job_slice = slice
134
+ count = 0
136
135
 
137
- processed_records = 0
138
136
  run_callbacks(:slice) do
139
137
  # Allow before_slice callbacks to fail, complete or abort this slice.
140
138
  return 0 unless running?
141
139
 
142
- RocketJob::Sliced::Writer::Output.collect(self, slice) do |writer|
143
- slice.each do |record|
144
- SemanticLogger.named_tagged(record: @rocket_job_record_number) do
145
- writer << rocket_job_batch_perform(slice, record, &block)
146
- processed_records += 1
147
- end
148
- # JRuby thinks self.rocket_job_record_number= is private and cannot be accessed
149
- @rocket_job_record_number += 1
150
- end
151
- end
152
- @rocket_job_slice = nil
153
- @rocket_job_record_number = nil
140
+ count = rocket_job_perform_slice(slice, &block)
154
141
  end
142
+ @rocket_job_slice = nil
155
143
 
156
144
  # On successful completion remove the slice from the input queue
157
145
  # TODO: Add option to complete slice instead of destroying it to retain input data.
158
146
  slice.destroy
159
- processed_records
147
+ count
148
+ end
149
+
150
+ # Perform individual slice without callbacks
151
+ def rocket_job_perform_slice(slice, &block)
152
+ count = 0
153
+ RocketJob::Sliced::Writer::Output.collect(self, slice) do |writer|
154
+ records = slice.records
155
+ slice.processing_record_number ||= 0
156
+
157
+ # Skip records already processed, if any.
158
+ # TODO: Must append to existing output slices before this can be enabled.
159
+ # if !collect_output && (slice.processing_record_number > 1)
160
+ # records = records[slice.processing_record_number - 1..-1]
161
+ # end
162
+
163
+ records.each do |record|
164
+ slice.processing_record_number += 1
165
+ SemanticLogger.named_tagged(record: slice.current_record_number) do
166
+ writer << rocket_job_batch_perform(slice, record, &block)
167
+ count += 1
168
+ end
169
+ end
170
+ end
171
+ count
160
172
  end
161
173
 
162
174
  # Perform a single record within the current slice.
163
175
  def rocket_job_batch_perform(slice, record)
164
- slice.processing_record_number ||= 0
165
- slice.processing_record_number += 1
176
+ @rocket_job_record_number = slice.current_record_number
166
177
 
167
178
  return block_given? ? yield(record) : perform(record) if _perform_callbacks.empty?
168
179
 
169
180
  # @rocket_job_input and @rocket_job_output can be modified by before/around callbacks
170
- @rocket_job_input = record
171
- @rocket_job_output = nil
181
+ @rocket_job_input = record
182
+ @rocket_job_output = nil
172
183
 
173
184
  run_callbacks(:perform) do
174
185
  @rocket_job_output =
@@ -179,9 +190,9 @@ module RocketJob
179
190
  end
180
191
  end
181
192
 
182
- @rocket_job_input = nil
183
- result = @rocket_job_output
184
- @rocket_job_output = nil
193
+ @rocket_job_input = nil
194
+ result = @rocket_job_output
195
+ @rocket_job_output = nil
185
196
  result
186
197
  end
187
198
 
@@ -197,24 +208,7 @@ module RocketJob
197
208
  if failed_count.positive? && (input_count == failed_count)
198
209
  # Reload to pull in any counters or other data that was modified.
199
210
  reload unless new_record?
200
- if may_fail?
201
- fail_job = true
202
- unless new_record?
203
- # Fail job iff no other worker has already finished it
204
- # Must set write concern to at least 1 since we need the nModified back
205
- result = self.class.with(write: {w: 1}) do |query|
206
- query.
207
- where(id: id, state: :running, sub_state: :processing).
208
- update({"$set" => {state: :failed, worker_name: worker_name}})
209
- end
210
- fail_job = false unless result.modified_count.positive?
211
- end
212
- if fail_job
213
- message = "#{failed_count} slices failed to process"
214
- self.exception = JobException.new(message: message)
215
- fail!(worker_name, message)
216
- end
217
- end
211
+ rocket_job_batch_fail!(worker_name) if may_fail?
218
212
  return true
219
213
  end
220
214
 
@@ -237,15 +231,38 @@ module RocketJob
237
231
 
238
232
  # Reload to pull in any counters or other data that was modified.
239
233
  reload
234
+
240
235
  if result.modified_count.positive?
241
236
  rocket_job_batch_run_after_callbacks(false)
242
- else
237
+ elsif aborted?
243
238
  # Repeat cleanup in case this worker was still running when the job was aborted
244
- cleanup! if aborted?
239
+ cleanup!
245
240
  end
246
241
  true
247
242
  end
248
243
 
244
+ # Fail the job
245
+ def rocket_job_batch_fail!(worker_name)
246
+ fail_job = true
247
+
248
+ unless new_record?
249
+ # Fail job iff no other worker has already finished it
250
+ # Must set write concern to at least 1 since we need the nModified back
251
+ result = self.class.with(write: {w: 1}) do |query|
252
+ query.
253
+ where(id: id, state: :running, sub_state: :processing).
254
+ update({"$set" => {state: :failed, worker_name: worker_name}})
255
+ end
256
+ fail_job = false unless result.modified_count.positive?
257
+ end
258
+
259
+ return unless fail_job
260
+
261
+ message = "#{input.failed.count} slices failed to process"
262
+ self.exception = JobException.new(message: message)
263
+ new_record? ? fail(worker_name, message) : fail!(worker_name, message)
264
+ end
265
+
249
266
  # Run the before_batch callbacks
250
267
  # Saves the current state before and after running callbacks if callbacks present
251
268
  def rocket_job_batch_run_before_callbacks
@@ -25,8 +25,8 @@ module RocketJob
25
25
 
26
26
  # The record number of the first record in this slice.
27
27
  # Useful in knowing the line number of each record in this slice
28
- # relative to the original file that was uploaded.
29
- field :first_record_number, type: Integer
28
+ # relative to the original file that was uploaded. (1-based index)
29
+ field :first_record_number, type: Integer, default: 1
30
30
 
31
31
  #
32
32
  # Read-only attributes
@@ -41,7 +41,7 @@ module RocketJob
41
41
  # Number of times that this job has failed to process
42
42
  field :failure_count, type: Integer
43
43
 
44
- # Number of the record within this slice (not the entire file/job) currently being processed. (One based index)
44
+ # Number of the record within this slice (not the entire file/job) currently being processed. (1-based index)
45
45
  field :processing_record_number, type: Integer
46
46
 
47
47
  # This name of the worker that this job is being processed by, or was processed by
@@ -112,7 +112,7 @@ module RocketJob
112
112
 
113
113
  # Returns [Integer] the record number of the record currently being processed relative to the entire file.
114
114
  def current_record_number
115
- first_record_number.to_i + processing_record_number.to_i
115
+ first_record_number + (processing_record_number || 1) - 1
116
116
  end
117
117
 
118
118
  # Before Fail save the exception to this slice.
@@ -1,3 +1,3 @@
1
1
  module RocketJob
2
- VERSION = "5.2.0.beta2".freeze
2
+ VERSION = "5.2.0.beta3".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rocketjob
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.2.0.beta2
4
+ version: 5.2.0.beta3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Reid Morrison
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-06 00:00:00.000000000 Z
11
+ date: 2020-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aasm