From d2987582f1e4a001fa2e8a4ec158ce1c5c17c123 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Mon, 29 Apr 2024 10:06:33 +0200 Subject: [PATCH] chore(blob): add maintenance task to recompute blob checksum --- .../recompute_blob_checksum_task.rb | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 app/tasks/maintenance/recompute_blob_checksum_task.rb diff --git a/app/tasks/maintenance/recompute_blob_checksum_task.rb b/app/tasks/maintenance/recompute_blob_checksum_task.rb new file mode 100644 index 000000000..628ea9bd7 --- /dev/null +++ b/app/tasks/maintenance/recompute_blob_checksum_task.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +module Maintenance + class RecomputeBlobChecksumTask < MaintenanceTasks::Task + attribute :blob_ids, :string + validates :blob_ids, presence: true + + def collection + ids = blob_ids.split(',').map(&:strip).map(&:to_i) + ActiveStorage::Blob.where(id: ids) + end + + def process(blob) + blob.upload(StringIO.new(blob.download), identify: false) + blob.save! + 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