From cbc13c4c5c1051dabfdf6f279673ff5f76fba96c Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Wed, 18 Sep 2024 16:33:36 +0200 Subject: [PATCH] feat(tasks): prefix tasks with timestamp --- config/initializers/maintenance_tasks.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 config/initializers/maintenance_tasks.rb diff --git a/config/initializers/maintenance_tasks.rb b/config/initializers/maintenance_tasks.rb new file mode 100644 index 000000000..1be27793e --- /dev/null +++ b/config/initializers/maintenance_tasks.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +Rails.application.config.after_initialize do + if defined?(Rails::Generators) + require "generators/maintenance_tasks/task_generator" + + class MaintenanceTasks::TaskGenerator + alias_method :original_assign_names!, :assign_names! + + private + + # Prefix the task name with a date so the tasks are better sorted. + def assign_names!(name) + timestamped_name = "T#{Date.current.strftime("%Y%m%d")}#{name}" + original_assign_names!(timestamped_name) + end + end + end +end