maintenance_tasks 2.15.0 → 2.16.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: 5504bbe129c76305465fce6a4cb5310feb2c0fd0fe2516a1896f60615825e183
4
+ data.tar.gz: 3a1cbf3fc0eef572d7b8e1451331e33618e8a1b888cde2cf8d39e0c6363b6a6a
5
5
  SHA512:
6
- metadata.gz: 22bde697fa7b38899ff5dc4c7fc353776a29766f479a3fac4f988b921aaf62bd58534f55a2c9caa1b9bf227ddbbef249c1d521b863afc5ab59527ad32528a4e9
7
- data.tar.gz: 1f51f3e1ead4af15d02886b950562e0a103baf055839e1e5e6f661b2dfd29d47626859fbd350e8d311293c88d4b4f59189ae70e32a8dbca54559d75ce5fafaa5
6
+ metadata.gz: e59152a9747d77adf137470e375ad68d06b07b410c73879f14f3d5cb418f26abe831102b32f6e5868f8824a2999f43ca4fdd0ad6a7eb84e85fbdb9d4e1530db7
7
+ data.tar.gz: 07bda592ce0919dc2487eb1df8ea585addbdaab8a8bca20c9f67332e3b5f8f04b6b2a66231de112e919a646352453a707f9909d857d5d57c7c58f9c4d46c8337
@@ -146,7 +146,7 @@ module MaintenanceTasks
146
146
 
147
147
  def on_start
148
148
  count = @task.count
149
- count = @collection_enum.size if count == :no_count
149
+ count = @collection_enum.size if count == NO_COUNT_DEFINED
150
150
  @run.start(count)
151
151
  end
152
152
 
@@ -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
 
@@ -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.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify Engineering
@@ -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.16.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.11
204
204
  specification_version: 4
205
205
  summary: A Rails engine for queuing and managing maintenance tasks
206
206
  test_files: []