job-iteration 1.1.5 → 1.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6bea2b43448343cc53903fdd896e7affd5d168f6c758ddf4b53a9d86de2207b8
4
- data.tar.gz: f74eabf96862da75494f80f6964c4e9a1611c6f46f66af23a6c8682ec595bcb1
3
+ metadata.gz: 1aa0774feb655e564e01134b940375a88b52eed719e9ff07bfbadb16c4515b7e
4
+ data.tar.gz: 54a0dd49a916affafc03122db00a2adbc0069268854fae00b751a35db92ebad4
5
5
  SHA512:
6
- metadata.gz: 0f32960627142f5fb14c8021e58347b491db9c75338eb323a6a7e3535569669f3f1a6f3482fd388ad471ece1293f5dee74d898384ce0f3d181c73c9adf480cb1
7
- data.tar.gz: 31a7cebea521cc632716d6f612ff1979f3f5efe4742305d2823a364c06930b9a4ece7043315a2cbb88c37db41c6d90a18dba1713458ea450acae3dd41ea18b79
6
+ metadata.gz: 0d1c6b08ef33f876c8fa692ce655f74502758eb6c0e3a98253d9cbb8a29c67906af2a3cbc317dc103a948c514b9eccad9e5938abc2e803f7f3aa25e4a49e9807
7
+ data.tar.gz: 3693719f3764bf8e158c568a7b63ed8c1b28174016b3d69fc5743711de99f4ad7bb3e80e29f9851e504e50b52ec1783aade73a7a7ee48b03718a9463aa11e98f
@@ -4,6 +4,11 @@
4
4
 
5
5
  #### Bug fix
6
6
 
7
+ ## v1.1.6 (May 22, 2020)
8
+
9
+ - [49](https://github.com/Shopify/job-iteration/pull/49) - Log when enumerator has nothing to iterate
10
+ - [52](https://github.com/Shopify/job-iteration/pull/52) - Fix CSVEnumerator cursor to properly remove already processed rows
11
+
7
12
  ## v1.1.5 (February 27, 2020)
8
13
 
9
14
  - [47](https://github.com/Shopify/job-iteration/pull/47) - Optional `sorbet-runtime` support for `JobIteration::Iteration` interface validation
@@ -8,7 +8,7 @@ class ListJob < ActiveJob::Base
8
8
 
9
9
  def build_enumerator(*)
10
10
  @redis = Redis.new
11
- Enumerator.new |yielder|
11
+ Enumerator.new do |yielder|
12
12
  yielder.yield @redis.lpop(key), nil
13
13
  end
14
14
  end
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.require_paths = %w(lib)
24
24
 
25
25
  spec.metadata["changelog_uri"] = "https://github.com/Shopify/job-iteration/blob/master/CHANGELOG.md"
26
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
26
27
 
27
28
  spec.add_development_dependency("activerecord")
28
29
  spec.add_dependency("activejob", ">= 5.2")
@@ -32,8 +32,8 @@ module JobIteration
32
32
  def rows(cursor:)
33
33
  @csv.lazy
34
34
  .each_with_index
35
- .drop(cursor.to_i)
36
- .to_enum { count_rows_in_file }
35
+ .drop(count_of_processed_rows(cursor))
36
+ .to_enum { count_of_rows_in_file }
37
37
  end
38
38
 
39
39
  # Constructs a enumerator on batches of CSV rows
@@ -42,13 +42,13 @@ module JobIteration
42
42
  @csv.lazy
43
43
  .each_slice(batch_size)
44
44
  .each_with_index
45
- .drop(cursor.to_i)
46
- .to_enum { (count_rows_in_file.to_f / batch_size).ceil }
45
+ .drop(count_of_processed_rows(cursor))
46
+ .to_enum { (count_of_rows_in_file.to_f / batch_size).ceil }
47
47
  end
48
48
 
49
49
  private
50
50
 
51
- def count_rows_in_file
51
+ def count_of_rows_in_file
52
52
  # TODO: Remove rescue for NoMethodError when Ruby 2.6 is no longer supported.
53
53
  begin
54
54
  filepath = @csv.path
@@ -63,5 +63,9 @@ module JobIteration
63
63
  count -= 1 if @csv.headers
64
64
  count
65
65
  end
66
+
67
+ def count_of_processed_rows(cursor)
68
+ cursor.nil? ? 0 : cursor + 1
69
+ end
66
70
  end
67
71
  end
@@ -116,8 +116,10 @@ module JobIteration
116
116
 
117
117
  def iterate_with_enumerator(enumerator, arguments)
118
118
  arguments = arguments.dup.freeze
119
+ found_record = false
119
120
  enumerator.each do |object_from_enumerator, index|
120
121
  record_unit_of_work do
122
+ found_record = true
121
123
  each_iteration(object_from_enumerator, *arguments)
122
124
  self.cursor_position = index
123
125
  end
@@ -128,6 +130,11 @@ module JobIteration
128
130
  return false
129
131
  end
130
132
 
133
+ logger.info(
134
+ "[JobIteration::Iteration] Enumerator found nothing to iterate! " \
135
+ "times_interrupted=#{times_interrupted} cursor_position=#{cursor_position}"
136
+ ) unless found_record
137
+
131
138
  true
132
139
  end
133
140
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JobIteration
4
- VERSION = "1.1.5"
4
+ VERSION = "1.1.6"
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.5
4
+ version: 1.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-02-28 00:00:00.000000000 Z
11
+ date: 2020-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -81,6 +81,7 @@ licenses:
81
81
  - MIT
82
82
  metadata:
83
83
  changelog_uri: https://github.com/Shopify/job-iteration/blob/master/CHANGELOG.md
84
+ allowed_push_host: https://rubygems.org
84
85
  post_install_message:
85
86
  rdoc_options: []
86
87
  require_paths: