maintenance_tasks 2.8.0 → 2.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +19 -2
- data/app/helpers/maintenance_tasks/tasks_helper.rb +29 -5
- data/app/models/maintenance_tasks/run.rb +13 -33
- data/lib/patches/active_record_batch_enumerator.rb +17 -16
- metadata +13 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f05710c874610ef0698738773b70923d2e6a4ec4ae4b452ac768b6bf2e696d2c
|
4
|
+
data.tar.gz: 2ab31dae65aa383d5edbccee747199960f5167cd33833230c044fd00f0ad6cfc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f0f7eee33cc6615f658f49ec9d74322f7952f2afa47b4b539dd0a49131cea10df15f072402d51d611bbfbf4d8d297ace54da1896ab457e54280bc17284641c9
|
7
|
+
data.tar.gz: af3992b2c6de8c8b70d840d8c06d6a8cb2646063a9b23222a1814bfc1cc7866a9745277aafe32ef8ee48627b7916e51c672c9321be87a49a5efd443f353722fc
|
data/README.md
CHANGED
@@ -485,6 +485,23 @@ to run. Since arguments are specified in the user interface via text area
|
|
485
485
|
inputs, it’s important to check that they conform to the format your Task
|
486
486
|
expects, and to sanitize any inputs if necessary.
|
487
487
|
|
488
|
+
#### Validating Task Parameters
|
489
|
+
|
490
|
+
Task attributes can be validated using Active Model Validations. Attributes are
|
491
|
+
validated before a Task is enqueued.
|
492
|
+
|
493
|
+
If an attribute uses an inclusion validator with a supported `in:` option, the
|
494
|
+
set of values will be used to populate a dropdown in the user interface. The
|
495
|
+
following types are supported:
|
496
|
+
|
497
|
+
* Arrays
|
498
|
+
* Procs and lambdas that optionally accept the Task instance, and return an Array.
|
499
|
+
* Callable objects that receive one argument, the Task instance, and return an Array.
|
500
|
+
* Methods that return an Array, called on the Task instance.
|
501
|
+
|
502
|
+
For enumerables that don't match the supported types, a text field will be
|
503
|
+
rendered instead.
|
504
|
+
|
488
505
|
### Custom cursor columns to improve performance
|
489
506
|
|
490
507
|
The [job-iteration gem][job-iteration], on which this gem depends, adds an
|
@@ -541,8 +558,8 @@ your application.
|
|
541
558
|
|
542
559
|
Usage example:
|
543
560
|
|
544
|
-
|
545
|
-
|
561
|
+
```ruby
|
562
|
+
ActiveSupport::Notifications.subscribe("succeeded.maintenance_tasks") do |*, payload|
|
546
563
|
task_name = payload[:task_name]
|
547
564
|
arguments = payload[:arguments]
|
548
565
|
metadata = payload[:metadata]
|
@@ -102,8 +102,13 @@ module MaintenanceTasks
|
|
102
102
|
end
|
103
103
|
|
104
104
|
# Resolves values covered by the inclusion validator for a task attribute.
|
105
|
-
#
|
106
|
-
#
|
105
|
+
# Supported option types:
|
106
|
+
# - Arrays
|
107
|
+
# - Procs and lambdas that optionally accept the Task instance, and return an Array.
|
108
|
+
# - Callable objects that receive one argument, the Task instance, and return an Array.
|
109
|
+
# - Methods that return an Array, called on the Task instance.
|
110
|
+
#
|
111
|
+
# Other types are not supported and will return nil.
|
107
112
|
#
|
108
113
|
# Returned values are used to populate a dropdown list of options.
|
109
114
|
#
|
@@ -111,20 +116,39 @@ module MaintenanceTasks
|
|
111
116
|
# @param parameter_name [String] The parameter name.
|
112
117
|
#
|
113
118
|
# @return [Array] value of the resolved inclusion option.
|
114
|
-
def resolve_inclusion_value(
|
119
|
+
def resolve_inclusion_value(task, parameter_name)
|
120
|
+
task_class = task.class
|
115
121
|
inclusion_validator = task_class.validators_on(parameter_name).find do |validator|
|
116
122
|
validator.kind == :inclusion
|
117
123
|
end
|
118
124
|
return unless inclusion_validator
|
119
125
|
|
120
126
|
in_option = inclusion_validator.options[:in] || inclusion_validator.options[:within]
|
121
|
-
|
127
|
+
resolved_in_option = case in_option
|
128
|
+
when Proc
|
129
|
+
if in_option.arity == 0
|
130
|
+
in_option.call
|
131
|
+
else
|
132
|
+
in_option.call(task)
|
133
|
+
end
|
134
|
+
when Symbol
|
135
|
+
method = task.method(in_option)
|
136
|
+
method.call if method.arity.zero?
|
137
|
+
else
|
138
|
+
if in_option.respond_to?(:call)
|
139
|
+
in_option.call(task)
|
140
|
+
else
|
141
|
+
in_option
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
resolved_in_option if resolved_in_option.is_a?(Array)
|
122
146
|
end
|
123
147
|
|
124
148
|
# Return the appropriate field tag for the parameter, based on its type.
|
125
149
|
# If the parameter has a `validates_inclusion_of` validator, return a dropdown list of options instead.
|
126
150
|
def parameter_field(form_builder, parameter_name)
|
127
|
-
inclusion_values = resolve_inclusion_value(form_builder.object
|
151
|
+
inclusion_values = resolve_inclusion_value(form_builder.object, parameter_name)
|
128
152
|
return form_builder.select(parameter_name, inclusion_values, prompt: "Select a value") if inclusion_values
|
129
153
|
|
130
154
|
case form_builder.object.class.attribute_types[parameter_name]
|
@@ -386,40 +386,20 @@ module MaintenanceTasks
|
|
386
386
|
nil
|
387
387
|
end
|
388
388
|
|
389
|
-
#
|
390
|
-
#
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
:arguments,
|
401
|
-
"are invalid: #{error_messages.join("; ")}",
|
402
|
-
)
|
403
|
-
end
|
404
|
-
rescue Task::NotFoundError
|
405
|
-
nil
|
406
|
-
end
|
407
|
-
else
|
408
|
-
# Performs validation on the arguments to use for the Task. If the Task is
|
409
|
-
# invalid, the errors are added to the Run.
|
410
|
-
def validate_task_arguments
|
411
|
-
arguments_match_task_attributes if arguments.present?
|
412
|
-
if task.invalid?
|
413
|
-
error_messages = task.errors
|
414
|
-
.map { |error| "#{error.attribute.inspect} #{error.message}" }
|
415
|
-
errors.add(
|
416
|
-
:arguments,
|
417
|
-
"are invalid: #{error_messages.join("; ")}",
|
418
|
-
)
|
419
|
-
end
|
420
|
-
rescue Task::NotFoundError
|
421
|
-
nil
|
389
|
+
# Performs validation on the arguments to use for the Task. If the Task is
|
390
|
+
# invalid, the errors are added to the Run.
|
391
|
+
def validate_task_arguments
|
392
|
+
arguments_match_task_attributes if arguments.present?
|
393
|
+
if task.invalid?
|
394
|
+
error_messages = task.errors
|
395
|
+
.map { |error| "#{error.attribute.inspect} #{error.message}" }
|
396
|
+
errors.add(
|
397
|
+
:arguments,
|
398
|
+
"are invalid: #{error_messages.join("; ")}",
|
399
|
+
)
|
422
400
|
end
|
401
|
+
rescue Task::NotFoundError
|
402
|
+
nil
|
423
403
|
end
|
424
404
|
|
425
405
|
# Fetches the attached ActiveStorage CSV file for the run. Checks first
|
@@ -1,23 +1,24 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
#
|
5
|
-
module ActiveRecordBatchEnumerator
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
if Rails.gem_version < Gem::Version.new("7.0")
|
4
|
+
# Add attribute readers.
|
5
|
+
module ActiveRecordBatchEnumerator
|
6
|
+
# The primary key value from which the BatchEnumerator starts,
|
7
|
+
# inclusive of the value.
|
8
|
+
attr_reader :start
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
# The primary key value at which the BatchEnumerator ends,
|
11
|
+
# inclusive of the value.
|
12
|
+
attr_reader :finish
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
# The relation from which the BatchEnumerator yields batches.
|
15
|
+
attr_reader :relation
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
# The size of the batches yielded by the BatchEnumerator.
|
18
|
+
def batch_size
|
19
|
+
@of
|
20
|
+
end
|
20
21
|
end
|
21
|
-
end
|
22
22
|
|
23
|
-
ActiveRecord::Batches::BatchEnumerator.include(ActiveRecordBatchEnumerator)
|
23
|
+
ActiveRecord::Batches::BatchEnumerator.include(ActiveRecordBatchEnumerator)
|
24
|
+
end
|
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.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shopify Engineering
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-11-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -16,42 +16,42 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '6.
|
19
|
+
version: '6.1'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '6.
|
26
|
+
version: '6.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activejob
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '6.
|
33
|
+
version: '6.1'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '6.
|
40
|
+
version: '6.1'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: activerecord
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '6.
|
47
|
+
version: '6.1'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '6.
|
54
|
+
version: '6.1'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: csv
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,14 +86,14 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '6.
|
89
|
+
version: '6.1'
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '6.
|
96
|
+
version: '6.1'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: zeitwerk
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -185,7 +185,7 @@ 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.9.0
|
189
189
|
allowed_push_host: https://rubygems.org
|
190
190
|
post_install_message:
|
191
191
|
rdoc_options: []
|
@@ -195,14 +195,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
195
195
|
requirements:
|
196
196
|
- - ">="
|
197
197
|
- !ruby/object:Gem::Version
|
198
|
-
version: '3.
|
198
|
+
version: '3.1'
|
199
199
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
200
200
|
requirements:
|
201
201
|
- - ">="
|
202
202
|
- !ruby/object:Gem::Version
|
203
203
|
version: '0'
|
204
204
|
requirements: []
|
205
|
-
rubygems_version: 3.5.
|
205
|
+
rubygems_version: 3.5.23
|
206
206
|
signing_key:
|
207
207
|
specification_version: 4
|
208
208
|
summary: A Rails engine for queuing and managing maintenance tasks
|