From c0ae02f458fdf1780d7faea517aa9c5ae11f4ace Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Thu, 19 Sep 2024 13:25:21 +0200 Subject: [PATCH] feat(tasks): use our task template, with example doc --- config/initializers/maintenance_tasks.rb | 1 + lib/templates/maintenance_tasks/task.rb.tt | 25 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 lib/templates/maintenance_tasks/task.rb.tt diff --git a/config/initializers/maintenance_tasks.rb b/config/initializers/maintenance_tasks.rb index 1be27793e..90e1bed87 100644 --- a/config/initializers/maintenance_tasks.rb +++ b/config/initializers/maintenance_tasks.rb @@ -6,6 +6,7 @@ Rails.application.config.after_initialize do class MaintenanceTasks::TaskGenerator alias_method :original_assign_names!, :assign_names! + source_paths << Rails.root.join("lib/templates/maintenance_tasks") private diff --git a/lib/templates/maintenance_tasks/task.rb.tt b/lib/templates/maintenance_tasks/task.rb.tt new file mode 100644 index 000000000..ef2e399ca --- /dev/null +++ b/lib/templates/maintenance_tasks/task.rb.tt @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +module <%= tasks_module %> +<% module_namespacing do -%> + class <%= class_name %>Task < MaintenanceTasks::Task + # Documentation: cette tâche modifie les données pour… + + def collection + # Collection to be iterated over + # Must be Active Record Relation or Array + end + + def process(element) + # The work to be done in a single iteration of the task. + # This should be idempotent, as the same element may be processed more + # than once if the task is interrupted and resumed. + end + + def count + # Optionally, define the number of rows that will be iterated over + # This is used to track the task's progress + end + end +<% end -%> +end