maintenance_tasks 2.15.0 → 2.17.0

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: f74ab248a9b57875d5e7b47234598a46fbc37033fb7d96c95e26b03c55d83793
4
- data.tar.gz: cf2322966430eee4215131e9885aba07591d2e6f5081f6ab1683188ae5be8e80
3
+ metadata.gz: cd230e758c366ce730cdfdb91a7ba7ae433582d69f01c78c828f22ae756401b7
4
+ data.tar.gz: fb3dd9d633b907e3ceaae6c7db7ed84c75b033f1832bd175f143fb590fcd0379
5
5
  SHA512:
6
- metadata.gz: 22bde697fa7b38899ff5dc4c7fc353776a29766f479a3fac4f988b921aaf62bd58534f55a2c9caa1b9bf227ddbbef249c1d521b863afc5ab59527ad32528a4e9
7
- data.tar.gz: 1f51f3e1ead4af15d02886b950562e0a103baf055839e1e5e6f661b2dfd29d47626859fbd350e8d311293c88d4b4f59189ae70e32a8dbca54559d75ce5fafaa5
6
+ metadata.gz: 850d1e302af870bbbd8a83c5a6db4b2080661ddd29d5a56e1f0e77e54e8cab983d56fe43fab39a14cf4031083e1df2345dad4901c035d689e744246d838a98db
7
+ data.tar.gz: d7bcab900521437f9e2ccf921f4213c28d688bc484a39920f05236184dc0072a5d929fcc81940e708ffeda7ef482e7787d96d52cf495b3f19568fd0058f6c328
data/README.md CHANGED
@@ -1047,6 +1047,8 @@ Reports to the error reporter will contain the following data:
1047
1047
  * `run_id`: The id of the errored Task run
1048
1048
  * `tick_count`: The tick count at the time of the error
1049
1049
  * `errored_element`: The element, if any, that was being processed when the
1050
+ Task errored. Active Record elements are reported as a hash with
1051
+ `class_name` and `id` keys.
1050
1052
  * `source`: This will be `maintenance-tasks`
1051
1053
  * `handled`: the value of `MaintenanceTasks.report_errors_as_handled` (default `true`, see below)
1052
1054
 
@@ -42,6 +42,15 @@ module MaintenanceTasks
42
42
  @run.cursor
43
43
  end
44
44
 
45
+ def serialized_errored_element(errored_element)
46
+ return errored_element unless errored_element.is_a?(ActiveRecord::Base)
47
+
48
+ {
49
+ class_name: errored_element.class.name,
50
+ id: errored_element.id,
51
+ }
52
+ end
53
+
45
54
  def build_enumerator(_run, cursor:)
46
55
  cursor ||= deserialized_run_cursor
47
56
  self.cursor_position = cursor
@@ -146,7 +155,7 @@ module MaintenanceTasks
146
155
 
147
156
  def on_start
148
157
  count = @task.count
149
- count = @collection_enum.size if count == :no_count
158
+ count = @collection_enum.size if count == NO_COUNT_DEFINED
150
159
  @run.start(count)
151
160
  end
152
161
 
@@ -206,10 +215,15 @@ module MaintenanceTasks
206
215
  errored_element = task_context.delete(:errored_element)
207
216
  MaintenanceTasks.error_handler.call(error, task_context.except(:run_id, :tick_count), errored_element)
208
217
  else
218
+ report_context = task_context.dup
219
+ if report_context.key?(:errored_element)
220
+ report_context[:errored_element] = serialized_errored_element(report_context[:errored_element])
221
+ end
222
+
209
223
  Rails.error.report(
210
224
  error,
211
225
  handled: MaintenanceTasks.report_errors_as_handled,
212
- context: task_context,
226
+ context: report_context,
213
227
  source: "maintenance-tasks",
214
228
  )
215
229
  end
@@ -8,35 +8,36 @@ module MaintenanceTasks
8
8
  module RunConcern
9
9
  extend ActiveSupport::Concern
10
10
 
11
- included do
12
- # Various statuses a run can be in.
13
- STATUSES = [
14
- :enqueued, # The task has been enqueued by the user.
15
- :running, # The task is being performed by a job worker.
16
- :succeeded, # The task finished without error.
17
- :cancelling, # The task has been told to cancel but is finishing work.
18
- :cancelled, # The user explicitly halted the task's execution.
19
- :interrupted, # The task was interrupted by the job infrastructure.
20
- :pausing, # The task has been told to pause but is finishing work.
21
- :paused, # The task was paused in the middle of the run by the user.
22
- :errored, # The task code produced an unhandled exception.
23
- ]
24
-
25
- ACTIVE_STATUSES = [
26
- :enqueued,
27
- :running,
28
- :paused,
29
- :pausing,
30
- :cancelling,
31
- :interrupted,
32
- ]
33
- STOPPING_STATUSES = [
34
- :pausing,
35
- :cancelling,
36
- :cancelled,
37
- ]
38
- COMPLETED_STATUSES = [:succeeded, :errored, :cancelled]
11
+ STATUSES = [
12
+ :enqueued, # The task has been enqueued by the user.
13
+ :running, # The task is being performed by a job worker.
14
+ :succeeded, # The task finished without error.
15
+ :cancelling, # The task has been told to cancel but is finishing work.
16
+ :cancelled, # The user explicitly halted the task's execution.
17
+ :interrupted, # The task was interrupted by the job infrastructure.
18
+ :pausing, # The task has been told to pause but is finishing work.
19
+ :paused, # The task was paused in the middle of the run by the user.
20
+ :errored, # The task code produced an unhandled exception.
21
+ ].freeze
22
+
23
+ ACTIVE_STATUSES = [
24
+ :enqueued,
25
+ :running,
26
+ :paused,
27
+ :pausing,
28
+ :cancelling,
29
+ :interrupted,
30
+ ].freeze
31
+
32
+ STOPPING_STATUSES = [
33
+ :pausing,
34
+ :cancelling,
35
+ :cancelled,
36
+ ].freeze
37
+
38
+ COMPLETED_STATUSES = [:succeeded, :errored, :cancelled].freeze
39
39
 
40
+ included do
40
41
  enum :status, STATUSES.to_h { |status| [status, status.to_s] }
41
42
 
42
43
  after_save :instrument_status_change
@@ -22,7 +22,7 @@ module MaintenanceTasks
22
22
  #
23
23
  # @return [Integer, nil]
24
24
  def count(task)
25
- :no_count
25
+ NO_COUNT_DEFINED
26
26
  end
27
27
 
28
28
  # Return that the Task does not process CSV content.
@@ -15,7 +15,9 @@ module MaintenanceTasks
15
15
  # Returns a list of sorted Task Data objects that represent the
16
16
  # available Tasks.
17
17
  #
18
- # Tasks are sorted by category, and within a category, by Task name.
18
+ # Tasks are sorted by category, and within a category, by the most
19
+ # recent Run's creation time (most recent first). New tasks with no
20
+ # Run history fall back to alphabetical order by name.
19
21
  # Determining a Task's category requires their latest Run records.
20
22
  # Two queries are done to get the currently active and completed Run
21
23
  # records, and Task Data instances are initialized with these related run
@@ -41,10 +43,13 @@ module MaintenanceTasks
41
43
  tasks << TaskDataIndex.new(task_name, last_run)
42
44
  end
43
45
 
44
- # We add an additional sorting key (status) to avoid possible
45
- # inconsistencies across database adapters when a Task has
46
- # multiple active Runs.
47
- tasks.sort_by! { |task| [task.name, task.status] }
46
+ # Most-recent-first by Run creation time; new tasks (no Run) sort
47
+ # together by name. Status is a final tiebreaker to keep ordering
48
+ # stable across database adapters when a Task has multiple active
49
+ # Runs created at the same time.
50
+ tasks.sort_by! do |task|
51
+ [-(task.related_run&.created_at&.to_f || 0), task.name, task.status]
52
+ end
48
53
  end
49
54
  end
50
55
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class AddCursorIsJsonFlagToRuns < ActiveRecord::Migration[7.1]
3
+ class AddCursorIsJsonFlagToRuns < ActiveRecord::Migration[7.2]
4
4
  def change
5
5
  add_column(:maintenance_tasks_runs, :cursor_is_json, :boolean, default: false, null: false)
6
6
  end
@@ -145,6 +145,11 @@ module MaintenanceTasks
145
145
  # @return [ActiveSupport::Duration, false] time interval after which a task is considered stale.
146
146
  mattr_accessor :task_staleness_threshold, default: 30.days
147
147
 
148
+ NO_COUNT_DEFINED = Object.new
149
+ NO_COUNT_DEFINED.define_singleton_method(:inspect) { "MaintenanceTasks::NO_COUNT_DEFINED" }
150
+ NO_COUNT_DEFINED.freeze
151
+ private_constant :NO_COUNT_DEFINED
152
+
148
153
  class << self
149
154
  DEPRECATION_MESSAGE = "MaintenanceTasks.error_handler is deprecated and will be removed in the 3.0 release. " \
150
155
  "Instead, reports will be sent to the Rails error reporter. Do not set a handler and subscribe " \
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maintenance_tasks
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.15.0
4
+ version: 2.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify Engineering
@@ -15,42 +15,42 @@ dependencies:
15
15
  requirements:
16
16
  - - ">="
17
17
  - !ruby/object:Gem::Version
18
- version: '7.1'
18
+ version: '7.2'
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - ">="
24
24
  - !ruby/object:Gem::Version
25
- version: '7.1'
25
+ version: '7.2'
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: activejob
28
28
  requirement: !ruby/object:Gem::Requirement
29
29
  requirements:
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: '7.1'
32
+ version: '7.2'
33
33
  type: :runtime
34
34
  prerelease: false
35
35
  version_requirements: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: '7.1'
39
+ version: '7.2'
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: activerecord
42
42
  requirement: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - ">="
45
45
  - !ruby/object:Gem::Version
46
- version: '7.1'
46
+ version: '7.2'
47
47
  type: :runtime
48
48
  prerelease: false
49
49
  version_requirements: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - ">="
52
52
  - !ruby/object:Gem::Version
53
- version: '7.1'
53
+ version: '7.2'
54
54
  - !ruby/object:Gem::Dependency
55
55
  name: csv
56
56
  requirement: !ruby/object:Gem::Requirement
@@ -85,14 +85,14 @@ dependencies:
85
85
  requirements:
86
86
  - - ">="
87
87
  - !ruby/object:Gem::Version
88
- version: '7.1'
88
+ version: '7.2'
89
89
  type: :runtime
90
90
  prerelease: false
91
91
  version_requirements: !ruby/object:Gem::Requirement
92
92
  requirements:
93
93
  - - ">="
94
94
  - !ruby/object:Gem::Version
95
- version: '7.1'
95
+ version: '7.2'
96
96
  - !ruby/object:Gem::Dependency
97
97
  name: zeitwerk
98
98
  requirement: !ruby/object:Gem::Requirement
@@ -184,7 +184,7 @@ homepage: https://github.com/Shopify/maintenance_tasks
184
184
  licenses:
185
185
  - MIT
186
186
  metadata:
187
- source_code_uri: https://github.com/Shopify/maintenance_tasks/tree/v2.15.0
187
+ source_code_uri: https://github.com/Shopify/maintenance_tasks/tree/v2.17.0
188
188
  allowed_push_host: https://rubygems.org
189
189
  rdoc_options: []
190
190
  require_paths:
@@ -200,7 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
200
200
  - !ruby/object:Gem::Version
201
201
  version: '0'
202
202
  requirements: []
203
- rubygems_version: 4.0.10
203
+ rubygems_version: 4.0.12
204
204
  specification_version: 4
205
205
  summary: A Rails engine for queuing and managing maintenance tasks
206
206
  test_files: []