You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -114,12 +116,12 @@ The typical Maintenance Tasks workflow is as follows:
114
116
1.[Generate a class describing the Task](#creating-a-task) and the work to be
115
117
done.
116
118
2. Run the Task
117
-
- either by [using the included web UI](#running-a-task-from-the-web-ui),
118
-
- or by [using the command line](#running-a-task-from-the-command-line),
119
-
- or by [using Ruby](#running-a-task-from-ruby).
119
+
- either by [using the included web UI](#running-a-task-from-the-web-ui),
120
+
- or by [using the command line](#running-a-task-from-the-command-line),
121
+
- or by [using Ruby](#running-a-task-from-ruby).
120
122
3.[Monitor the Task](#monitoring-your-tasks-status)
121
-
- either by using the included web UI,
122
-
- or by manually checking your task’s run’s status in your database.
123
+
- either by using the included web UI,
124
+
- or by manually checking your task’s run’s status in your database.
123
125
4. Optionally, delete the Task code if you no longer need it.
124
126
125
127
### Creating a Task
@@ -168,7 +170,8 @@ end
168
170
When processing records from an Active Record Relation, records are fetched in
169
171
batches internally, and then each record is passed to the `#process` method.
170
172
Maintenance Tasks will query the database to fetch records in batches of 100 by
171
-
default, but the batch size can be modified using the `collection_batch_size` macro:
173
+
default, but the batch size can be modified using the `collection_batch_size`
174
+
macro:
172
175
173
176
```ruby
174
177
# app/tasks/maintenance/update_posts_task.rb
@@ -502,33 +505,39 @@ set of values will be used to populate a dropdown in the user interface. The
502
505
following types are supported:
503
506
504
507
* Arrays
505
-
* Procs and lambdas that optionally accept the Task instance, and return an Array.
506
-
* Callable objects that receive one argument, the Task instance, and return an Array.
508
+
* Procs and lambdas that optionally accept the Task instance, and return an
509
+
Array.
510
+
* Callable objects that receive one argument, the Task instance, and return an
511
+
Array.
507
512
* Methods that return an Array, called on the Task instance.
508
513
509
514
For enumerables that don't match the supported types, a text field will be
510
515
rendered instead.
511
516
512
517
### Masking Task Parameters
513
-
Task attributes can be masked in the UI by adding `mask_attribute` class method in the
514
-
task class.
515
-
This will replace the value in the arguments list with `[FILTERED]` in the UI.
518
+
519
+
Task attributes can be masked in the UI by adding `mask_attribute` class method
520
+
in the task class. This will replace the value in the arguments list with
521
+
`[FILTERED]` in the UI.
516
522
517
523
```ruby
518
524
# app/tasks/maintenance/sensitive_params_task.rb
519
525
520
526
moduleMaintenance
521
527
classSensitiveParamsTask < MaintenanceTasks::Task
522
528
attribute :sensitive_content, :string
523
-
529
+
524
530
mask_attribute :sensitive_content
525
531
end
526
532
end
527
533
```
528
534
529
-
If you have any filtered parameters in the global [rails parameter filter](https://guides.rubyonrails.org/configuring.html#config-filter-parameters), they will be
530
-
automatically taken into account when masking the parameters, which means that you can mask parameters
531
-
across all tasks by adding them to the global rails parameters filter.
535
+
If you have any filtered parameters in the global [Rails parameter
536
+
filter][rails-parameter-filter], they will be automatically taken into account
537
+
when masking the parameters, which means that you can mask parameters across all
538
+
tasks by adding them to the global rails parameters filter.
@@ -1018,45 +1027,45 @@ be placed in a `maintenance_tasks.rb` initializer.
1018
1027
Exceptions raised while a Task is performing are rescued and information about
1019
1028
the error is persisted and visible in the UI.
1020
1029
1021
-
Errors are also sent to the `Rails.error.reporter`, which can be configured by your
1022
-
application. See the [Error Reporting in Rails Applications](https://guides.rubyonrails.org/error_reporting.html) guide for more details.
1030
+
Errors are also sent to the `Rails.error.reporter`, which can be configured by
1031
+
your application. See the [Error Reporting in Rails
1032
+
Applications][rails-error-reporting] guide for more details.
1023
1033
1024
1034
Reports to the error reporter will contain the following data:
1025
1035
1026
1036
*`error`: The exception that was raised.
1027
-
*`context`: A hash with additional information about the Task and the
1028
-
error:
1029
-
*`task_name`: The name of the Task that errored
1030
-
*`started_at`: The time the Task started
1031
-
*`ended_at`: The time the Task errored
1032
-
*`run_id`: The id of the errored Task run
1033
-
*`tick_count`: The tick count at the time of the error
1034
-
*`errored_element`: The element, if any, that was being processed when the Task
1035
-
raised an exception. If you would like to pass this object to your exception
1036
-
monitoring service, make sure you **sanitize the object** to avoid leaking
1037
-
sensitive data and **convert it to a format** that is compatible with your bug
1038
-
tracker.
1037
+
*`context`: A hash with additional information about the Task and the error:
1038
+
*`task_name`: The name of the Task that errored
1039
+
*`started_at`: The time the Task started
1040
+
*`ended_at`: The time the Task errored
1041
+
*`run_id`: The id of the errored Task run
1042
+
*`tick_count`: The tick count at the time of the error
1043
+
*`errored_element`: The element, if any, that was being processed when the
1039
1044
*`source`: This will be `maintenance-tasks`
1040
1045
1041
1046
Note that `context` may be empty if the Task produced an error before any
1042
-
context could be gathered (for example, if deserializing the job to process
1043
-
your Task failed).
1047
+
context could be gathered (for example, if deserializing the job to process your
1048
+
Task failed).
1044
1049
1045
1050
#### Reporting errors during iteration
1046
1051
1047
-
By default, errors raised during task iteration will be raised to the application
1048
-
and iteration will stop. However, you may want to handle some errors and continue
1049
-
iteration. `MaintenanceTasks::Task.report_on` can be used to rescue certain
1050
-
exceptions and report them to the Rails error reporter. Any keyword arguments are passed to [report](https://api.rubyonrails.org/classes/ActiveSupport/ErrorReporter.html#method-i-report):
1052
+
By default, errors raised during task iteration will be raised to the
1053
+
application and iteration will stop. However, you may want to handle some errors
1054
+
and continue iteration. `MaintenanceTasks::Task.report_on` can be used to rescue
1055
+
certain exceptions and report them to the Rails error reporter. Any keyword
0 commit comments