maintenance_tasks 2.13.0 → 2.15.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 +4 -4
- data/README.md +49 -3
- data/app/controllers/maintenance_tasks/application_controller.rb +1 -1
- data/app/helpers/maintenance_tasks/tasks_helper.rb +1 -1
- data/app/jobs/concerns/maintenance_tasks/task_job_concern.rb +15 -3
- data/app/models/concerns/maintenance_tasks/run_concern.rb +567 -0
- data/app/models/maintenance_tasks/run.rb +1 -513
- data/app/models/maintenance_tasks/runner.rb +2 -0
- data/app/models/maintenance_tasks/task_data_index.rb +9 -0
- data/app/views/layouts/maintenance_tasks/_navbar.html.erb +1 -1
- data/app/views/layouts/maintenance_tasks/application.html.erb +43 -12
- data/app/views/maintenance_tasks/runs/_run.html.erb +1 -1
- data/app/views/maintenance_tasks/runs/info/_errored.html.erb +1 -1
- data/app/views/maintenance_tasks/runs/info/_paused.html.erb +1 -1
- data/app/views/maintenance_tasks/runs/info/_running.html.erb +1 -1
- data/app/views/maintenance_tasks/runs/info/_succeeded.html.erb +0 -1
- data/app/views/maintenance_tasks/tasks/_task.html.erb +13 -1
- data/app/views/maintenance_tasks/tasks/index.html.erb +2 -2
- data/app/views/maintenance_tasks/tasks/show.html.erb +2 -2
- data/db/migrate/20251128180556_add_cursor_is_json_flag_to_runs.rb +7 -0
- data/lib/maintenance_tasks.rb +36 -0
- metadata +5 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f74ab248a9b57875d5e7b47234598a46fbc37033fb7d96c95e26b03c55d83793
|
|
4
|
+
data.tar.gz: cf2322966430eee4215131e9885aba07591d2e6f5081f6ab1683188ae5be8e80
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 22bde697fa7b38899ff5dc4c7fc353776a29766f479a3fac4f988b921aaf62bd58534f55a2c9caa1b9bf227ddbbef249c1d521b863afc5ab59527ad32528a4e9
|
|
7
|
+
data.tar.gz: 1f51f3e1ead4af15d02886b950562e0a103baf055839e1e5e6f661b2dfd29d47626859fbd350e8d311293c88d4b4f59189ae70e32a8dbca54559d75ce5fafaa5
|
data/README.md
CHANGED
|
@@ -242,8 +242,8 @@ seconds to process. Consider skipping the count (defining a `count` that returns
|
|
|
242
242
|
`nil`) or use an approximation, eg: count the number of new lines:
|
|
243
243
|
|
|
244
244
|
```ruby
|
|
245
|
-
def count
|
|
246
|
-
|
|
245
|
+
def count
|
|
246
|
+
csv_content.count("\n") - 1
|
|
247
247
|
end
|
|
248
248
|
```
|
|
249
249
|
|
|
@@ -391,7 +391,10 @@ This method should return an `Enumerator`, yielding pairs of `[item, cursor]`.
|
|
|
391
391
|
Maintenance Tasks takes care of persisting the current cursor position and will
|
|
392
392
|
provide it as the `cursor` argument if your task is interrupted or resumed. The
|
|
393
393
|
`cursor` is stored as a `String`, so your custom enumerator should handle
|
|
394
|
-
serializing/deserializing the value if required.
|
|
394
|
+
serializing/deserializing the value if required. Note that if you've enabled
|
|
395
|
+
[JSON cursors](#json-cursors), the cursor will be automatically serialized and
|
|
396
|
+
deserialized. However for this to work, the cursor values must be
|
|
397
|
+
JSON-serializable.
|
|
395
398
|
|
|
396
399
|
```ruby
|
|
397
400
|
# app/tasks/maintenance/custom_enumerator_task.rb
|
|
@@ -561,6 +564,9 @@ control the cursor columns, through the `cursor_columns` method in the
|
|
|
561
564
|
the query is ordered by the primary key. If cursor columns values change during
|
|
562
565
|
an iteration, records may be skipped or yielded multiple times.
|
|
563
566
|
|
|
567
|
+
Note that in order to use this feature, you must first enable
|
|
568
|
+
[JSON cursors](#json-cursors).
|
|
569
|
+
|
|
564
570
|
```ruby
|
|
565
571
|
module Maintenance
|
|
566
572
|
class UpdatePostsTask < MaintenanceTasks::Task
|
|
@@ -1317,6 +1323,46 @@ MaintenanceTasks.metadata = ->() do
|
|
|
1317
1323
|
end
|
|
1318
1324
|
```
|
|
1319
1325
|
|
|
1326
|
+
#### JSON Cursors
|
|
1327
|
+
|
|
1328
|
+
By default, cursor values are persisted in the database as a string. If you
|
|
1329
|
+
want to iterate over collections that require multiple values to keep track of
|
|
1330
|
+
the position, you can enable JSON cursors. This will cause the cursor to be
|
|
1331
|
+
serialized as JSON when persisted, and deserialized when read back.
|
|
1332
|
+
|
|
1333
|
+
This is especially useful when you need to iterate over a model that uses a
|
|
1334
|
+
composite primary key.
|
|
1335
|
+
|
|
1336
|
+
Be advised that this feature comes with a few caveats:
|
|
1337
|
+
|
|
1338
|
+
1. Cursor values must be capable of being serialized to JSON and parsed from
|
|
1339
|
+
JSON. If they are not, errors will occur during task execution.
|
|
1340
|
+
2. If a cursor contains a value that loses precision when serialized, it may
|
|
1341
|
+
lead to unexpected behaviour.
|
|
1342
|
+
3. This feature utilizes a string column to store the JSON data. If your
|
|
1343
|
+
database has a hard limit on how big a string value can be, be mindful that
|
|
1344
|
+
certain cursor structures could result in a value that could exceed that
|
|
1345
|
+
limit and cause issues.
|
|
1346
|
+
|
|
1347
|
+
A new column was added to discern JSON cursors from plain string cursors. Make
|
|
1348
|
+
sure you have run the latest database migrations provided by the gem before
|
|
1349
|
+
enabling this feature. See [upgrading](#upgrading) for more information.
|
|
1350
|
+
|
|
1351
|
+
```ruby
|
|
1352
|
+
# config/initializers/maintenance_tasks.rb
|
|
1353
|
+
MaintenanceTasks.serialize_cursors_as_json = true
|
|
1354
|
+
```
|
|
1355
|
+
|
|
1356
|
+
#### Configure staleness threshold
|
|
1357
|
+
|
|
1358
|
+
To specify a staleness threshold date interval which will mark task runs as stale, you can
|
|
1359
|
+
configure `MaintenanceTasks.task_staleness_threshold`. Tasks that have last run
|
|
1360
|
+
successfully after this threshold will be marked stale.
|
|
1361
|
+
|
|
1362
|
+
The value for `MaintenanceTasks.task_staleness_threshold` must be an
|
|
1363
|
+
`ActiveSupport::Duration`. If no value is specified, it will default to 30 days. This can be disabled
|
|
1364
|
+
by setting `MaintenanceTasks.task_staleness_threshold` to `false`.
|
|
1365
|
+
|
|
1320
1366
|
## Upgrading
|
|
1321
1367
|
|
|
1322
1368
|
Use bundler to check for and upgrade to newer versions. After installing a new
|
|
@@ -11,7 +11,7 @@ module MaintenanceTasks
|
|
|
11
11
|
policy.style_src_elem(
|
|
12
12
|
BULMA_CDN,
|
|
13
13
|
# <style> tag in app/views/layouts/maintenance_tasks/application.html.erb
|
|
14
|
-
"'sha256-
|
|
14
|
+
"'sha256-b9tTK1UaF0U8792/A1vIUkeZwjPgECIOeKJdhYED06A='",
|
|
15
15
|
)
|
|
16
16
|
capybara_lockstep_scripts = [
|
|
17
17
|
"'sha256-1AoN3ZtJC5OvqkMgrYvhZjp4kI8QjJjO7TAyKYiDw+U='",
|
|
@@ -62,7 +62,7 @@ module MaintenanceTasks
|
|
|
62
62
|
def status_tag(status)
|
|
63
63
|
tag.span(
|
|
64
64
|
status.capitalize,
|
|
65
|
-
class: ["tag", "has-text-weight-medium", "
|
|
65
|
+
class: ["tag", "has-text-weight-medium", "px-2", "mx-4"] + STATUS_COLOURS.fetch(status),
|
|
66
66
|
)
|
|
67
67
|
end
|
|
68
68
|
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "json"
|
|
4
|
+
|
|
3
5
|
module MaintenanceTasks
|
|
4
6
|
# Concern that holds the behaviour of the job that runs the tasks. It is
|
|
5
7
|
# included in {TaskJob} and if MaintenanceTasks.job is overridden, it must be
|
|
@@ -30,8 +32,18 @@ module MaintenanceTasks
|
|
|
30
32
|
|
|
31
33
|
private
|
|
32
34
|
|
|
35
|
+
def serialized_cursor_position
|
|
36
|
+
cursor_position && @run.cursor_is_json? ? cursor_position.to_json : cursor_position
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def deserialized_run_cursor
|
|
40
|
+
return JSON.parse(@run.cursor) if @run.cursor && @run.cursor_is_json?
|
|
41
|
+
|
|
42
|
+
@run.cursor
|
|
43
|
+
end
|
|
44
|
+
|
|
33
45
|
def build_enumerator(_run, cursor:)
|
|
34
|
-
cursor ||=
|
|
46
|
+
cursor ||= deserialized_run_cursor
|
|
35
47
|
self.cursor_position = cursor
|
|
36
48
|
enumerator_builder = self.enumerator_builder
|
|
37
49
|
@collection_enum = @task.enumerator_builder(cursor: cursor)
|
|
@@ -140,7 +152,7 @@ module MaintenanceTasks
|
|
|
140
152
|
|
|
141
153
|
def on_shutdown
|
|
142
154
|
@run.job_shutdown
|
|
143
|
-
@run.cursor =
|
|
155
|
+
@run.cursor = serialized_cursor_position
|
|
144
156
|
@ticker.persist
|
|
145
157
|
end
|
|
146
158
|
|
|
@@ -177,7 +189,7 @@ module MaintenanceTasks
|
|
|
177
189
|
@ticker.persist if defined?(@ticker)
|
|
178
190
|
|
|
179
191
|
if defined?(@run)
|
|
180
|
-
@run.cursor =
|
|
192
|
+
@run.cursor = serialized_cursor_position
|
|
181
193
|
@run.persist_error(error)
|
|
182
194
|
|
|
183
195
|
task_context = {
|