From 3939f85860229a8b05f6f2f34de6cfcc05366317 Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Tue, 13 Jun 2023 16:27:16 +0200 Subject: [PATCH] refactor(job): wrap sentry tags in a single before_perform --- app/jobs/application_job.rb | 11 +++++++++++ app/jobs/archive_creation_job.rb | 4 ---- app/jobs/export_job.rb | 4 ---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb index cd19f09c6..f9c3a8b34 100644 --- a/app/jobs/application_job.rb +++ b/app/jobs/application_job.rb @@ -5,6 +5,17 @@ class ApplicationJob < ActiveJob::Base attr_writer :request_id + before_perform do |job| + arg = job.arguments.first + + case arg + when Dossier + Sentry.set_tags(dossier: arg.id, procedure: arg.procedure.id) + when Procedure + Sentry.set_tags(procedure: arg.id) + end + end + around_perform do |job, block| Rails.logger.info("#{job.class.name} started at #{Time.zone.now}") Current.set(request_id: job.request_id) do diff --git a/app/jobs/archive_creation_job.rb b/app/jobs/archive_creation_job.rb index 7c00a60f3..661996ffb 100644 --- a/app/jobs/archive_creation_job.rb +++ b/app/jobs/archive_creation_job.rb @@ -1,10 +1,6 @@ class ArchiveCreationJob < ApplicationJob queue_as :archives - before_perform do |job| - Sentry.set_tags(procedure: job.arguments.first.id) - end - def max_run_time Archive::MAX_DUREE_GENERATION end diff --git a/app/jobs/export_job.rb b/app/jobs/export_job.rb index 86ce5fefb..0ea91c844 100644 --- a/app/jobs/export_job.rb +++ b/app/jobs/export_job.rb @@ -3,10 +3,6 @@ class ExportJob < ApplicationJob discard_on ActiveRecord::RecordNotFound - before_perform do |job| - Sentry.set_tags(procedure: job.arguments.first.procedure.id) - end - def max_run_time Export::MAX_DUREE_GENERATION end