job-iteration 1.17.0 → 1.18.1

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: 657313f73892dc576ba595499f00d97a211936bdbec570db64e72c7431aa0a11
4
- data.tar.gz: f12f068e6a83efc6fd702e4c5068c8b428587ec2b94eb9087c00e7141f689dee
3
+ metadata.gz: ee75f098d2b1a3eed6fb0690cb9f7f28d08c35d2dc214585c1ca915f74677df7
4
+ data.tar.gz: 36ea172bc286dd7133c04094918dd16e2f8b0401ea4c16dbd85b14f0528224b1
5
5
  SHA512:
6
- metadata.gz: dd60d3982a00af5e2193739c0e9e62adee8e08414628fa19a9f1d6d85f4ad1c5d9cbbd3b5a931b695fccdd50d60a5592a420a04c6eaa446f3b5cbf2e53beadb9
7
- data.tar.gz: 0e4c271a6a72a11bafcb5bb3fd362f88c2a90ee8b1ddb622c7053c0b0a8eed6b78b2420db0a28d448d7ce12026ad6313d409441567b30acc8e46a46a3243cfdc
6
+ metadata.gz: 4f570809a416c4c5f99dba36d8b59e99e904ae2c7dfad62216b0f43e0ae9189a4f8fbadba42c996a5d244258a2612bcf5fe5971080dd721ced61a702cce661c8
7
+ data.tar.gz: 0b6699c8c436e527e371a6f416c44ea435c3e3120fa6cabd6f2dc586190578df451b34daf3786026549bc7aebf5ed0e4d70596b2d49f00a71533661779041aeb
data/CHANGELOG.md CHANGED
@@ -16,6 +16,18 @@ nil
16
16
 
17
17
  nil
18
18
 
19
+ ## v1.18.1 (Nov 20, 2026)
20
+
21
+ ### Bug fixes
22
+
23
+ - [763](https://github.com/Shopify/job-iteration/pull/763) - Omit cursor values from the default no-record and interruption log messages to avoid exposing sensitive cursor data.
24
+
25
+ ## v1.18.0 (Nov 6, 2026)
26
+
27
+ ### Features
28
+
29
+ - [760](https://github.com/Shopify/job-iteration/pull/760) - Add the `serialize_cursor` and `deserialize_cursor` hooks, which a job overrides to decide how its cursor is stored in the job payload and rebuilt when it resumes; for example through `ActiveJob::Arguments`, so a `Time` or a custom id class survives the trip through JSON. The defaults keep the cursor as it is.
30
+
19
31
  ## v1.17.0 (Oct 27, 2026)
20
32
 
21
33
  ### Features
@@ -94,7 +94,7 @@ module JobIteration
94
94
 
95
95
  def serialize # @private
96
96
  super.merge(
97
- "cursor_position" => cursor_position,
97
+ "cursor_position" => serialize_cursor(cursor_position),
98
98
  "times_interrupted" => times_interrupted,
99
99
  "total_time" => total_time,
100
100
  )
@@ -102,11 +102,42 @@ module JobIteration
102
102
 
103
103
  def deserialize(job_data) # @private
104
104
  super
105
- self.cursor_position = job_data["cursor_position"]
105
+ self.cursor_position = deserialize_cursor(job_data["cursor_position"])
106
106
  self.times_interrupted = Integer(job_data["times_interrupted"] || 0)
107
107
  self.total_time = Float(job_data["total_time"] || 0.0)
108
108
  end
109
109
 
110
+ # Converts the cursor into the form stored in the job payload when the job is interrupted. The queue
111
+ # backend serializes that payload, typically as JSON, so by default a cursor has to be made of values
112
+ # JSON round-trips as the same objects: Strings, Integers, Floats, Arrays, Hashes, true, false, or nil.
113
+ #
114
+ # Override this method together with #deserialize_cursor to persist cursors of other types. Active Job's
115
+ # argument serialization is a natural choice: it already handles Time, Date, BigDecimal, Symbol and any
116
+ # class with an ActiveJob::Serializers::ObjectSerializer, and leaves JSON-native values untouched.
117
+ #
118
+ # def serialize_cursor(cursor)
119
+ # ActiveJob::Arguments.serialize([cursor]).first
120
+ # end
121
+ #
122
+ # def deserialize_cursor(cursor)
123
+ # ActiveJob::Arguments.deserialize([cursor]).first
124
+ # end
125
+ #
126
+ # @param cursor [Object] the cursor the enumerator yielded last
127
+ # @return [Object] what to store in the job payload
128
+ def serialize_cursor(cursor)
129
+ cursor
130
+ end
131
+
132
+ # Rebuilds the cursor from the form #serialize_cursor stored in the job payload, before it is passed to
133
+ # #build_enumerator as +cursor:+. The default returns it unchanged.
134
+ #
135
+ # @param cursor [Object] the stored cursor, as the queue backend deserialized it
136
+ # @return [Object] the cursor to resume from
137
+ def deserialize_cursor(cursor)
138
+ cursor
139
+ end
140
+
110
141
  def perform(...) # @private
111
142
  interruptible_perform(...)
112
143
 
@@ -184,7 +215,7 @@ module JobIteration
184
215
 
185
216
  enumerator.each do |object_from_enumerator, cursor_from_enumerator|
186
217
  # Deferred until 2.0.0
187
- # assert_valid_cursor!(cursor_from_enumerator)
218
+ # assert_valid_cursor!(serialize_cursor(cursor_from_enumerator))
188
219
 
189
220
  tags = instrumentation_tags.merge(cursor_position: cursor_from_enumerator)
190
221
  ActiveSupport::Notifications.instrument("each_iteration.iteration", tags) do
@@ -312,12 +343,14 @@ module JobIteration
312
343
 
313
344
  # The adapter must be able to serialize and deserialize the cursor back into an equivalent object.
314
345
  # https://github.com/mperham/sidekiq/wiki/Best-Practices#1-make-your-job-parameters-small-and-simple
346
+ # Validated on the result of #serialize_cursor, which is what reaches the adapter.
315
347
  def assert_valid_cursor!(cursor)
316
348
  return if serializable?(cursor)
317
349
 
318
350
  raise CursorError.new(
319
351
  "Cursor must be composed of objects capable of built-in (de)serialization: " \
320
- "Strings, Integers, Floats, Arrays, Hashes, true, false, or nil.",
352
+ "Strings, Integers, Floats, Arrays, Hashes, true, false, or nil. " \
353
+ "Override #serialize_cursor and #deserialize_cursor to persist other types.",
321
354
  cursor: cursor,
322
355
  )
323
356
  end
@@ -15,7 +15,7 @@ module JobIteration
15
15
  def not_found(event)
16
16
  info do
17
17
  "[JobIteration::Iteration] Enumerator found nothing to iterate! " \
18
- "times_interrupted=#{event.payload[:times_interrupted]} cursor_position=#{event.payload[:cursor_position]}"
18
+ "times_interrupted=#{event.payload[:times_interrupted]}"
19
19
  end
20
20
  end
21
21
 
@@ -36,7 +36,7 @@ module JobIteration
36
36
  def interrupted(event)
37
37
  info do
38
38
  "[JobIteration::Iteration] Interrupting and re-enqueueing the job " \
39
- "cursor_position=#{event.payload[:cursor_position]} reason=#{event.payload[:reason] || "nil"}"
39
+ "reason=#{event.payload[:reason] || "nil"}"
40
40
  end
41
41
  end
42
42
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JobIteration
4
- VERSION = "1.17.0"
4
+ VERSION = "1.18.1"
5
5
  end
@@ -23,7 +23,7 @@ module Tapioca
23
23
 
24
24
  sig { override.void }
25
25
  def decorate
26
- return unless constant.instance_methods(false).include?(:build_enumerator)
26
+ return unless constant.method_defined?(:build_enumerator, false)
27
27
 
28
28
  root.create_path(constant) do |job|
29
29
  method = constant.instance_method(:build_enumerator)
metadata CHANGED
@@ -1,84 +1,88 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: job-iteration
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.17.0
4
+ version: 1.18.1
5
5
  platform: ruby
6
6
  authors:
7
- - Shopify
7
+ - Shopify
8
8
  bindir: exe
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
- - !ruby/object:Gem::Dependency
13
- name: activejob
14
- requirement: !ruby/object:Gem::Requirement
15
- requirements:
16
- - - ">="
17
- - !ruby/object:Gem::Version
18
- version: '7.1'
19
- type: :runtime
20
- prerelease: false
21
- version_requirements: !ruby/object:Gem::Requirement
22
- requirements:
23
- - - ">="
24
- - !ruby/object:Gem::Version
25
- version: '7.1'
12
+ - !ruby/object:Gem::Dependency
13
+ name: activejob
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ -
17
+ - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: "7.1"
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ -
25
+ - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: "7.1"
26
28
  description: Makes your background jobs interruptible and resumable.
27
29
  email:
28
- - ops-accounts+shipit@shopify.com
30
+ - ops-accounts+shipit@shopify.com
29
31
  executables: []
30
32
  extensions: []
31
33
  extra_rdoc_files: []
32
34
  files:
33
- - CHANGELOG.md
34
- - LICENSE.txt
35
- - README.md
36
- - job-iteration.gemspec
37
- - lib/job-iteration.rb
38
- - lib/job-iteration/active_record_batch_enumerator.rb
39
- - lib/job-iteration/active_record_batch_enumerator/column_manager.rb
40
- - lib/job-iteration/active_record_cursor.rb
41
- - lib/job-iteration/active_record_enumerator.rb
42
- - lib/job-iteration/csv_enumerator.rb
43
- - lib/job-iteration/enumerator_builder.rb
44
- - lib/job-iteration/interruption_adapters.rb
45
- - lib/job-iteration/interruption_adapters/delayed_job_adapter.rb
46
- - lib/job-iteration/interruption_adapters/good_job_adapter.rb
47
- - lib/job-iteration/interruption_adapters/null_adapter.rb
48
- - lib/job-iteration/interruption_adapters/resque_adapter.rb
49
- - lib/job-iteration/interruption_adapters/sidekiq_adapter.rb
50
- - lib/job-iteration/interruption_adapters/solid_queue_adapter.rb
51
- - lib/job-iteration/interruption_adapters/sqs_adapter.rb
52
- - lib/job-iteration/iteration.rb
53
- - lib/job-iteration/log_subscriber.rb
54
- - lib/job-iteration/nested_enumerator.rb
55
- - lib/job-iteration/parallel_enumerator.rb
56
- - lib/job-iteration/railtie.rb
57
- - lib/job-iteration/test_helper.rb
58
- - lib/job-iteration/throttle_enumerator.rb
59
- - lib/job-iteration/version.rb
60
- - lib/tapioca/dsl/compilers/job_iteration.rb
61
- homepage: https://github.com/shopify/job-iteration
35
+ - CHANGELOG.md
36
+ - LICENSE.txt
37
+ - README.md
38
+ - job-iteration.gemspec
39
+ - lib/job-iteration.rb
40
+ - lib/job-iteration/active_record_batch_enumerator.rb
41
+ - lib/job-iteration/active_record_batch_enumerator/column_manager.rb
42
+ - lib/job-iteration/active_record_cursor.rb
43
+ - lib/job-iteration/active_record_enumerator.rb
44
+ - lib/job-iteration/csv_enumerator.rb
45
+ - lib/job-iteration/enumerator_builder.rb
46
+ - lib/job-iteration/interruption_adapters.rb
47
+ - lib/job-iteration/interruption_adapters/delayed_job_adapter.rb
48
+ - lib/job-iteration/interruption_adapters/good_job_adapter.rb
49
+ - lib/job-iteration/interruption_adapters/null_adapter.rb
50
+ - lib/job-iteration/interruption_adapters/resque_adapter.rb
51
+ - lib/job-iteration/interruption_adapters/sidekiq_adapter.rb
52
+ - lib/job-iteration/interruption_adapters/solid_queue_adapter.rb
53
+ - lib/job-iteration/interruption_adapters/sqs_adapter.rb
54
+ - lib/job-iteration/iteration.rb
55
+ - lib/job-iteration/log_subscriber.rb
56
+ - lib/job-iteration/nested_enumerator.rb
57
+ - lib/job-iteration/parallel_enumerator.rb
58
+ - lib/job-iteration/railtie.rb
59
+ - lib/job-iteration/test_helper.rb
60
+ - lib/job-iteration/throttle_enumerator.rb
61
+ - lib/job-iteration/version.rb
62
+ - lib/tapioca/dsl/compilers/job_iteration.rb
63
+ homepage: "https://github.com/shopify/job-iteration"
62
64
  licenses:
63
- - MIT
65
+ - MIT
64
66
  metadata:
65
- changelog_uri: https://github.com/Shopify/job-iteration/blob/main/CHANGELOG.md
66
- allowed_push_host: https://rubygems.org
67
+ changelog_uri: "https://github.com/Shopify/job-iteration/blob/main/CHANGELOG.md"
68
+ allowed_push_host: "https://rubygems.org"
67
69
  rdoc_options: []
68
70
  require_paths:
69
- - lib
71
+ - lib
70
72
  required_ruby_version: !ruby/object:Gem::Requirement
71
73
  requirements:
72
- - - ">="
73
- - !ruby/object:Gem::Version
74
- version: '3.1'
74
+ -
75
+ - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: "3.1"
75
78
  required_rubygems_version: !ruby/object:Gem::Requirement
76
79
  requirements:
77
- - - ">="
78
- - !ruby/object:Gem::Version
79
- version: '0'
80
+ -
81
+ - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: "0"
80
84
  requirements: []
81
- rubygems_version: 4.0.23
85
+ rubygems_version: 4.1.0
82
86
  specification_version: 4
83
87
  summary: Makes your background jobs interruptible and resumable.
84
88
  test_files: []