job-iteration 1.1.10 → 1.1.12

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: 7868f8da1aee096abee4d4a1848c2242d0a7ac9bb1b456ad8385cfe6421a902e
4
- data.tar.gz: fd82a4cdfcbff16220363e1c53aa064b0cd5e599e17290aa968fdb01d8fe4002
3
+ metadata.gz: 2109f33c06a85e1b336876ea4c0aafe2dc0ea7f17fbdda0d4bba06177f940113
4
+ data.tar.gz: 3ce3b8017f1dfaac8bb3c83f8b846c4068ed09a0968f937bb1bd3e31d9d1341a
5
5
  SHA512:
6
- metadata.gz: 42a601bb25a38571c97d108a8847317892a5289e2d3f8d818b68c99a49fc6d142dffcdd9191350261a89db65bf24aa3b0691057238f2416e2a0140bf16c47485
7
- data.tar.gz: 364868992c7fe4602f31d453891f4597d73d0b7b76482510d7ae9d3d3de7baf951465c5df7fcf9923592abb05b3584a9206f104bd610ab52dbbf3625c03be3f6
6
+ metadata.gz: d22611524765adb75a6d6cd457d2c1e0e7169621b3c9a2fd4f8fbcc4d68f7a79cf89764852a61f11bdd586ac60c1bb9d6c76f34426c5a1eb25299bd8b6ec77b7
7
+ data.tar.gz: 952569f76f1d9b739d4219bfb3df0878ef1ec1c3784bba985f2246a956a581c51723e113ca10ac9eec3f4c2ae61c6acaabd4d461aa321c1af989d1921293ef34
@@ -1,11 +1,11 @@
1
- name: Ruby
1
+ name: CI
2
2
 
3
3
  on: [push]
4
4
 
5
5
  jobs:
6
6
  build:
7
7
  runs-on: ubuntu-latest
8
- name: Ruby ${{ matrix.ruby }}
8
+ name: Ruby ${{ matrix.ruby }} | Gemfile ${{ matrix.gemfile }}
9
9
  services:
10
10
  redis:
11
11
  image: redis
data/CHANGELOG.md CHANGED
@@ -4,13 +4,26 @@
4
4
 
5
5
  #### Bug fix
6
6
 
7
+ ## v1.1.12 (April 19, 2021)
8
+
9
+ #### Bug fix
10
+
11
+ - [77](https://github.com/Shopify/job-iteration/pull/77) - Defer enforce cursor be serializable until 2.0.0
12
+
13
+ ## v1.1.11 (April 19, 2021)
14
+
15
+ #### Bug fix
16
+
17
+ - [73](https://github.com/Shopify/job-iteration/pull/73) - Enforce cursor be serializable
18
+ _This is reverted in 1.1.12 as it breaks behaviour in some apps._
19
+
7
20
  ## v1.1.10 (March 30, 2021)
8
21
 
9
- - [69](https://github.com/Shopify/job-iteration/pull/69) Fix memory leak in ActiveRecordCursor
22
+ - [69](https://github.com/Shopify/job-iteration/pull/69) - Fix memory leak in ActiveRecordCursor
10
23
 
11
24
  ## v1.1.9 (January 6, 2021)
12
25
 
13
- - [61](https://github.com/Shopify/job-iteration/pull/61) Call `super` in `method_added`
26
+ - [61](https://github.com/Shopify/job-iteration/pull/61) - Call `super` in `method_added`
14
27
 
15
28
  ## v1.1.8 (June 8, 2020)
16
29
 
data/Gemfile CHANGED
@@ -21,6 +21,7 @@ gem "pry"
21
21
  gem "mocha"
22
22
 
23
23
  gem "rubocop-shopify", require: false
24
+ gem "rubocop", "<= 1.12.1", require: false # 1.13.0 drops Ruby 2.4 support
24
25
  gem "yard"
25
26
  gem "rake"
26
27
 
@@ -6,6 +6,28 @@ module JobIteration
6
6
  module Iteration
7
7
  extend ActiveSupport::Concern
8
8
 
9
+ class CursorError < ArgumentError
10
+ attr_reader :cursor
11
+
12
+ def initialize(message, cursor:)
13
+ super(message)
14
+ @cursor = cursor
15
+ end
16
+
17
+ def message
18
+ "#{super} (#{inspected_cursor})"
19
+ end
20
+
21
+ private
22
+
23
+ def inspected_cursor
24
+ cursor.inspect
25
+ rescue NoMethodError
26
+ # For those brave enough to try to use BasicObject as cursor. Nice try.
27
+ Object.instance_method(:inspect).bind(cursor).call
28
+ end
29
+ end
30
+
9
31
  included do |_base|
10
32
  attr_accessor(
11
33
  :cursor_position,
@@ -120,6 +142,9 @@ module JobIteration
120
142
  arguments = arguments.dup.freeze
121
143
  found_record = false
122
144
  enumerator.each do |object_from_enumerator, index|
145
+ # Deferred until 2.0.0
146
+ # assert_valid_cursor!(index)
147
+
123
148
  record_unit_of_work do
124
149
  found_record = true
125
150
  each_iteration(object_from_enumerator, *arguments)
@@ -176,6 +201,18 @@ module JobIteration
176
201
  EOS
177
202
  end
178
203
 
204
+ # The adapter must be able to serialize and deserialize the cursor back into an equivalent object.
205
+ # https://github.com/mperham/sidekiq/wiki/Best-Practices#1-make-your-job-parameters-small-and-simple
206
+ def assert_valid_cursor!(cursor)
207
+ return if serializable?(cursor)
208
+
209
+ raise CursorError.new(
210
+ "Cursor must be composed of objects capable of built-in (de)serialization: " \
211
+ "Strings, Integers, Floats, Arrays, Hashes, true, false, or nil.",
212
+ cursor: cursor,
213
+ )
214
+ end
215
+
179
216
  def assert_implements_methods!
180
217
  unless respond_to?(:each_iteration, true)
181
218
  raise(
@@ -251,5 +288,21 @@ module JobIteration
251
288
  end
252
289
  false
253
290
  end
291
+
292
+ SIMPLE_SERIALIZABLE_CLASSES = [String, Integer, Float, NilClass, TrueClass, FalseClass].freeze
293
+ private_constant :SIMPLE_SERIALIZABLE_CLASSES
294
+ def serializable?(object)
295
+ # Subclasses must be excluded, hence not using is_a? or ===.
296
+ if object.instance_of?(Array)
297
+ object.all? { |element| serializable?(element) }
298
+ elsif object.instance_of?(Hash)
299
+ object.all? { |key, value| serializable?(key) && serializable?(value) }
300
+ else
301
+ SIMPLE_SERIALIZABLE_CLASSES.any? { |klass| object.instance_of?(klass) }
302
+ end
303
+ rescue NoMethodError
304
+ # BasicObject doesn't respond to instance_of, but we can't serialize it anyway
305
+ false
306
+ end
254
307
  end
255
308
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JobIteration
4
- VERSION = "1.1.10"
4
+ VERSION = "1.1.12"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: job-iteration
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.10
4
+ version: 1.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-30 00:00:00.000000000 Z
11
+ date: 2021-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -45,7 +45,7 @@ executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
- - ".github/workflows/ruby.yml"
48
+ - ".github/workflows/ci.yml"
49
49
  - ".gitignore"
50
50
  - ".rubocop.yml"
51
51
  - ".yardopts"