maintenance_tasks 2.7.1 → 2.8.0
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b984293788834b153823e857dad5020b8cca1902037c97fd158401c1da3cfee3
|
4
|
+
data.tar.gz: 0c079b820fbfd3d7e26e7c19585ac8b41199de92f7a71e671a63c7db46b60d06
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f43e5c6535246bf7259bb21cfd1eb3f48f356a9f1f2e83fea19096cdff8610a601d4ea96b623d63bbecbaa593d1022a34fd16210896f83852f64c3e3bf003b41
|
7
|
+
data.tar.gz: a506d5e89ec233e60a59c428801d8e2e79a57f6604f8ab9cf97882b71bf69f4304f7d1fa53ac33ecd4ab5bb76f9de3774cbf9d1bfdd7cdff52af1849379b7e6d
|
data/README.md
CHANGED
@@ -156,6 +156,32 @@ module Maintenance
|
|
156
156
|
end
|
157
157
|
```
|
158
158
|
|
159
|
+
#### Customizing the Batch Size
|
160
|
+
|
161
|
+
When processing records from an Active Record Relation, records are fetched in
|
162
|
+
batches internally, and then each record is passed to the `#process` method.
|
163
|
+
Maintenance Tasks will query the database to fetch records in batches of 100 by
|
164
|
+
default, but the batch size can be modified using the `collection_batch_size` macro:
|
165
|
+
|
166
|
+
```ruby
|
167
|
+
# app/tasks/maintenance/update_posts_task.rb
|
168
|
+
|
169
|
+
module Maintenance
|
170
|
+
class UpdatePostsTask < MaintenanceTasks::Task
|
171
|
+
# Fetch records in batches of 1000
|
172
|
+
collection_batch_size(1000)
|
173
|
+
|
174
|
+
def collection
|
175
|
+
Post.all
|
176
|
+
end
|
177
|
+
|
178
|
+
def process(post)
|
179
|
+
post.update!(content: "New content!")
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
```
|
184
|
+
|
159
185
|
### Creating a CSV Task
|
160
186
|
|
161
187
|
You can also write a Task that iterates on a CSV file. Note that writing CSV
|
@@ -727,9 +753,9 @@ end
|
|
727
753
|
### Writing tests for a Task that uses a custom enumerator
|
728
754
|
|
729
755
|
Tests for tasks that use custom enumerators need to instantiate the task class
|
730
|
-
in order to call `#
|
731
|
-
that `#
|
732
|
-
as expected.
|
756
|
+
in order to call `#enumerator_builder`. Once the task instance is set up,
|
757
|
+
validate that `#enumerator_builder` returns an enumerator yielding pairs of
|
758
|
+
`[item, cursor]` as expected.
|
733
759
|
|
734
760
|
```ruby
|
735
761
|
# test/tasks/maintenance/custom_enumerating_task.rb
|
@@ -742,8 +768,8 @@ module Maintenance
|
|
742
768
|
@task = CustomEnumeratingTask.new
|
743
769
|
end
|
744
770
|
|
745
|
-
test "#
|
746
|
-
enum = @task.
|
771
|
+
test "#enumerator_builder returns enumerator yielding pairs of [item, cursor]" do
|
772
|
+
enum = @task.enumerator_builder(cursor: 0)
|
747
773
|
expected_items = [:b, :c]
|
748
774
|
|
749
775
|
assert_equal 2, enum.size
|
@@ -39,7 +39,9 @@ module MaintenanceTasks
|
|
39
39
|
when :no_collection
|
40
40
|
enumerator_builder.build_once_enumerator(cursor: nil)
|
41
41
|
when ActiveRecord::Relation
|
42
|
-
|
42
|
+
options = { cursor: cursor, columns: @task.cursor_columns }
|
43
|
+
options[:batch_size] = @task.active_record_enumerator_batch_size if @task.active_record_enumerator_batch_size
|
44
|
+
enumerator_builder.active_record_on_records(collection, **options)
|
43
45
|
when ActiveRecord::Batches::BatchEnumerator
|
44
46
|
if collection.start || collection.finish
|
45
47
|
raise ArgumentError, <<~MSG.squish
|
@@ -164,6 +166,7 @@ module MaintenanceTasks
|
|
164
166
|
end
|
165
167
|
|
166
168
|
def on_error(error)
|
169
|
+
task_context = {}
|
167
170
|
@ticker.persist if defined?(@ticker)
|
168
171
|
|
169
172
|
if defined?(@run)
|
@@ -175,8 +178,6 @@ module MaintenanceTasks
|
|
175
178
|
started_at: @run.started_at,
|
176
179
|
ended_at: @run.ended_at,
|
177
180
|
}
|
178
|
-
else
|
179
|
-
task_context = {}
|
180
181
|
end
|
181
182
|
errored_element = @errored_element if defined?(@errored_element)
|
182
183
|
ensure
|
@@ -18,6 +18,12 @@ module MaintenanceTasks
|
|
18
18
|
# @api private
|
19
19
|
class_attribute :throttle_conditions, default: []
|
20
20
|
|
21
|
+
# The number of active records to fetch in a single query when iterating
|
22
|
+
# over an Active Record collection task.
|
23
|
+
#
|
24
|
+
# @api private
|
25
|
+
class_attribute :active_record_enumerator_batch_size
|
26
|
+
|
21
27
|
# @api private
|
22
28
|
class_attribute :collection_builder_strategy, default: NullCollectionBuilder.new
|
23
29
|
|
@@ -138,6 +144,14 @@ module MaintenanceTasks
|
|
138
144
|
self.throttle_conditions += [{ throttle_on: condition, backoff: backoff_as_proc }]
|
139
145
|
end
|
140
146
|
|
147
|
+
# Limit the number of records that will be fetched in a single query when
|
148
|
+
# iterating over an Active Record collection task.
|
149
|
+
#
|
150
|
+
# @param size [Integer] the number of records to fetch in a single query.
|
151
|
+
def collection_batch_size(size)
|
152
|
+
self.active_record_enumerator_batch_size = size
|
153
|
+
end
|
154
|
+
|
141
155
|
# Initialize a callback to run after the task starts.
|
142
156
|
#
|
143
157
|
# @param filter_list apply filters to the callback
|
@@ -44,7 +44,7 @@
|
|
44
44
|
|
45
45
|
<h4 class="title is-4">Active Runs</h4>
|
46
46
|
|
47
|
-
<%= render @task.active_runs %>
|
47
|
+
<%= render partial: "maintenance_tasks/runs/run", collection: @task.active_runs %>
|
48
48
|
<% end %>
|
49
49
|
|
50
50
|
<% if @runs_page.records.present? %>
|
@@ -52,7 +52,7 @@
|
|
52
52
|
|
53
53
|
<h4 class="title is-4">Previous Runs</h4>
|
54
54
|
|
55
|
-
<%= render @runs_page.records %>
|
55
|
+
<%= render partial: "maintenance_tasks/runs/run", collection: @runs_page.records %>
|
56
56
|
|
57
57
|
<%= link_to "Next page", task_path(@task, cursor: @runs_page.next_cursor) unless @runs_page.last? %>
|
58
58
|
<% end %>
|
@@ -10,7 +10,7 @@ module MaintenanceTasks
|
|
10
10
|
|
11
11
|
# Mounts the engine in the host application's config/routes.rb
|
12
12
|
def mount_engine
|
13
|
-
route("mount MaintenanceTasks::Engine
|
13
|
+
route("mount MaintenanceTasks::Engine, at: \"/maintenance_tasks\"")
|
14
14
|
end
|
15
15
|
|
16
16
|
# Copies engine migrations to host application and migrates the database
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: maintenance_tasks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shopify Engineering
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -108,7 +108,7 @@ dependencies:
|
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: 2.6.2
|
111
|
-
description:
|
111
|
+
description:
|
112
112
|
email: gems@shopify.com
|
113
113
|
executables:
|
114
114
|
- maintenance_tasks
|
@@ -185,9 +185,9 @@ homepage: https://github.com/Shopify/maintenance_tasks
|
|
185
185
|
licenses:
|
186
186
|
- MIT
|
187
187
|
metadata:
|
188
|
-
source_code_uri: https://github.com/Shopify/maintenance_tasks/tree/v2.
|
188
|
+
source_code_uri: https://github.com/Shopify/maintenance_tasks/tree/v2.8.0
|
189
189
|
allowed_push_host: https://rubygems.org
|
190
|
-
post_install_message:
|
190
|
+
post_install_message:
|
191
191
|
rdoc_options: []
|
192
192
|
require_paths:
|
193
193
|
- lib
|
@@ -202,8 +202,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
202
202
|
- !ruby/object:Gem::Version
|
203
203
|
version: '0'
|
204
204
|
requirements: []
|
205
|
-
rubygems_version: 3.5.
|
206
|
-
signing_key:
|
205
|
+
rubygems_version: 3.5.17
|
206
|
+
signing_key:
|
207
207
|
specification_version: 4
|
208
208
|
summary: A Rails engine for queuing and managing maintenance tasks
|
209
209
|
test_files: []
|