job-iteration 1.1.8 → 1.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +12 -6
- data/guides/custom-enumerator.md +2 -0
- data/lib/job-iteration/iteration.rb +1 -0
- data/lib/job-iteration/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a4821d55797f7597b3c916d6fbca2195c054bd3aab0ffcc40c9ce21ae0b1ec4
|
4
|
+
data.tar.gz: e71ce0fb7ec744b502f018ccfc7ea5e819bfe06f9fb2ca5a32c70cc1b875abc7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 943795fabf60cff76fa7b8678f1f5d5a83bd98340194e142092dc891ff1abe991c0410572cebd09155c6c220ff96aa5530fb27e1b4fe119c6bbbf22fe12670ef
|
7
|
+
data.tar.gz: 11ea6f0165aa31350c6486236a33d66c94316a08f52905aeaab049388b433c229ccf52e69ae3e43eb8bca9a5c56dc4aae46803aae4add9d2a052d5d49af14d8d
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -9,7 +9,7 @@ Meet Iteration, an extension for [ActiveJob](https://github.com/rails/rails/tree
|
|
9
9
|
Imagine the following job:
|
10
10
|
|
11
11
|
```ruby
|
12
|
-
class SimpleJob <
|
12
|
+
class SimpleJob < ApplicationJob
|
13
13
|
def perform
|
14
14
|
User.find_each do |user|
|
15
15
|
user.notify_about_something
|
@@ -43,7 +43,7 @@ And then execute:
|
|
43
43
|
In the job, include `JobIteration::Iteration` module and start describing the job with two methods (`build_enumerator` and `each_iteration`) instead of `perform`:
|
44
44
|
|
45
45
|
```ruby
|
46
|
-
class NotifyUsersJob <
|
46
|
+
class NotifyUsersJob < ApplicationJob
|
47
47
|
include JobIteration::Iteration
|
48
48
|
|
49
49
|
def build_enumerator(cursor:)
|
@@ -64,7 +64,9 @@ end
|
|
64
64
|
Check out more examples of Iterations:
|
65
65
|
|
66
66
|
```ruby
|
67
|
-
class BatchesJob <
|
67
|
+
class BatchesJob < ApplicationJob
|
68
|
+
include JobIteration::Iteration
|
69
|
+
|
68
70
|
def build_enumerator(product_id, cursor:)
|
69
71
|
enumerator_builder.active_record_on_batches(
|
70
72
|
Product.find(product_id).comments,
|
@@ -81,7 +83,9 @@ end
|
|
81
83
|
```
|
82
84
|
|
83
85
|
```ruby
|
84
|
-
class ArrayJob <
|
86
|
+
class ArrayJob < ApplicationJob
|
87
|
+
include JobIteration::Iteration
|
88
|
+
|
85
89
|
def build_enumerator(cursor:)
|
86
90
|
enumerator_builder.array(['build', 'enumerator', 'from', 'any', 'array'], cursor: cursor)
|
87
91
|
end
|
@@ -93,7 +97,9 @@ end
|
|
93
97
|
```
|
94
98
|
|
95
99
|
```ruby
|
96
|
-
class CsvJob <
|
100
|
+
class CsvJob < ApplicationJob
|
101
|
+
include JobIteration::Iteration
|
102
|
+
|
97
103
|
def build_enumerator(import_id, cursor:)
|
98
104
|
import = Import.find(import_id)
|
99
105
|
JobIteration::CsvEnumerator.new(import.csv).rows(cursor: cursor)
|
@@ -153,7 +159,7 @@ There a few configuration assumptions that are required for Iteration to work wi
|
|
153
159
|
**My job has a complex flow. How do I write my own Enumerator?** Iteration API takes care of persisting the cursor (that you may use to calculate an offset) and controlling the job state. The power of Enumerator object is that you can use the cursor in any way you want. One example is a cursorless job that pops records from a datastore until the job is interrupted:
|
154
160
|
|
155
161
|
```ruby
|
156
|
-
class MyJob <
|
162
|
+
class MyJob < ApplicationJob
|
157
163
|
include JobIteration::Iteration
|
158
164
|
|
159
165
|
def build_enumerator(cursor:)
|
data/guides/custom-enumerator.md
CHANGED
@@ -72,3 +72,5 @@ end
|
|
72
72
|
```
|
73
73
|
|
74
74
|
We recommend that you read the implementation of the other enumerators that come with the library (`CsvEnumerator`, `ActiveRecordEnumerator`) to gain a better understanding of building Enumerator objects.
|
75
|
+
|
76
|
+
Code that is written after the `yield` in a custom enumerator is not guaranteed to execute. In the case that a job is forced to exit ie `job_should_exit?` is true, then the job is re-enqueued during the yield and the rest of the code in the enumerator does not run. You can follow that logic [here](https://github.com/Shopify/job-iteration/blob/9641f455b9126efff2214692c0bef423e0d12c39/lib/job-iteration/iteration.rb#L128-L131).
|
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.
|
4
|
+
version: 1.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shopify
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|