From 513d4f6ff1541515d1f30daf3249e0e8a5e46f91 Mon Sep 17 00:00:00 2001 From: clemkeirua Date: Fri, 13 Nov 2020 14:34:53 +0100 Subject: [PATCH] move all the cron jobs in a dedicated directory --- .../administrateur_activate_before_expiration_job.rb | 2 +- app/jobs/{ => cron}/auto_archive_procedure_job.rb | 2 +- app/jobs/{ => cron}/cron_job.rb | 2 +- app/jobs/{ => cron}/declarative_procedures_job.rb | 2 +- app/jobs/{ => cron}/discarded_dossiers_deletion_job.rb | 2 +- app/jobs/{ => cron}/discarded_procedures_deletion_job.rb | 2 +- app/jobs/{ => cron}/expired_dossiers_deletion_job.rb | 2 +- app/jobs/{ => cron}/find_dubious_procedures_job.rb | 2 +- app/jobs/{ => cron}/instructeur_email_notification_job.rb | 2 +- app/jobs/{ => cron}/notify_draft_not_submitted_job.rb | 2 +- app/jobs/{ => cron}/operations_signature_job.rb | 2 +- app/jobs/{ => cron}/purge_stale_exports_job.rb | 2 +- app/jobs/{ => cron}/purge_unattached_blobs_job.rb | 2 +- .../update_administrateur_usage_statistics_job.rb | 2 +- app/jobs/{ => cron}/update_stats_job.rb | 2 +- app/jobs/{ => cron}/weekly_overview_job.rb | 2 +- .../administrateur_activate_before_expiration_job_spec.rb | 4 ++-- spec/jobs/{ => cron}/auto_archive_procedure_job_spec.rb | 4 ++-- spec/jobs/{ => cron}/declarative_procedures_job_spec.rb | 4 ++-- spec/jobs/{ => cron}/find_dubious_procedures_job_spec.rb | 4 ++-- spec/jobs/{ => cron}/weekly_overview_job_spec.rb | 8 ++++---- spec/models/instructeur_spec.rb | 6 +++--- spec/services/notification_service_spec.rb | 6 +++--- 23 files changed, 34 insertions(+), 34 deletions(-) rename app/jobs/{ => cron}/administrateur_activate_before_expiration_job.rb (76%) rename app/jobs/{ => cron}/auto_archive_procedure_job.rb (86%) rename app/jobs/{ => cron}/cron_job.rb (95%) rename app/jobs/{ => cron}/declarative_procedures_job.rb (71%) rename app/jobs/{ => cron}/discarded_dossiers_deletion_job.rb (77%) rename app/jobs/{ => cron}/discarded_procedures_deletion_job.rb (79%) rename app/jobs/{ => cron}/expired_dossiers_deletion_job.rb (80%) rename app/jobs/{ => cron}/find_dubious_procedures_job.rb (95%) rename app/jobs/{ => cron}/instructeur_email_notification_job.rb (72%) rename app/jobs/{ => cron}/notify_draft_not_submitted_job.rb (71%) rename app/jobs/{ => cron}/operations_signature_job.rb (89%) rename app/jobs/{ => cron}/purge_stale_exports_job.rb (67%) rename app/jobs/{ => cron}/purge_unattached_blobs_job.rb (80%) rename app/jobs/{ => cron}/update_administrateur_usage_statistics_job.rb (68%) rename app/jobs/{ => cron}/update_stats_job.rb (69%) rename app/jobs/{ => cron}/weekly_overview_job.rb (90%) rename spec/jobs/{ => cron}/administrateur_activate_before_expiration_job_spec.rb (93%) rename spec/jobs/{ => cron}/auto_archive_procedure_job_spec.rb (96%) rename spec/jobs/{ => cron}/declarative_procedures_job_spec.rb (96%) rename spec/jobs/{ => cron}/find_dubious_procedures_job_spec.rb (94%) rename spec/jobs/{ => cron}/weekly_overview_job_spec.rb (87%) diff --git a/app/jobs/administrateur_activate_before_expiration_job.rb b/app/jobs/cron/administrateur_activate_before_expiration_job.rb similarity index 76% rename from app/jobs/administrateur_activate_before_expiration_job.rb rename to app/jobs/cron/administrateur_activate_before_expiration_job.rb index 958ed9635..4c5c518e8 100644 --- a/app/jobs/administrateur_activate_before_expiration_job.rb +++ b/app/jobs/cron/administrateur_activate_before_expiration_job.rb @@ -1,4 +1,4 @@ -class AdministrateurActivateBeforeExpirationJob < CronJob +class Cron::AdministrateurActivateBeforeExpirationJob < Cron::CronJob self.schedule_expression = "every day at 8 am" def perform(*args) diff --git a/app/jobs/auto_archive_procedure_job.rb b/app/jobs/cron/auto_archive_procedure_job.rb similarity index 86% rename from app/jobs/auto_archive_procedure_job.rb rename to app/jobs/cron/auto_archive_procedure_job.rb index d8611b291..8887fda3c 100644 --- a/app/jobs/auto_archive_procedure_job.rb +++ b/app/jobs/cron/auto_archive_procedure_job.rb @@ -1,4 +1,4 @@ -class AutoArchiveProcedureJob < CronJob +class Cron::AutoArchiveProcedureJob < Cron::CronJob self.schedule_expression = "every 1 minute" def perform(*args) diff --git a/app/jobs/cron_job.rb b/app/jobs/cron/cron_job.rb similarity index 95% rename from app/jobs/cron_job.rb rename to app/jobs/cron/cron_job.rb index adbc74dd4..1fe79f81b 100644 --- a/app/jobs/cron_job.rb +++ b/app/jobs/cron/cron_job.rb @@ -1,4 +1,4 @@ -class CronJob < ApplicationJob +class Cron::CronJob < ApplicationJob queue_as :cron class_attribute :schedule_expression diff --git a/app/jobs/declarative_procedures_job.rb b/app/jobs/cron/declarative_procedures_job.rb similarity index 71% rename from app/jobs/declarative_procedures_job.rb rename to app/jobs/cron/declarative_procedures_job.rb index af2bb395c..4a2bc613d 100644 --- a/app/jobs/declarative_procedures_job.rb +++ b/app/jobs/cron/declarative_procedures_job.rb @@ -1,4 +1,4 @@ -class DeclarativeProceduresJob < CronJob +class Cron::DeclarativeProceduresJob < Cron::CronJob self.schedule_expression = "every 1 minute" def perform(*args) diff --git a/app/jobs/discarded_dossiers_deletion_job.rb b/app/jobs/cron/discarded_dossiers_deletion_job.rb similarity index 77% rename from app/jobs/discarded_dossiers_deletion_job.rb rename to app/jobs/cron/discarded_dossiers_deletion_job.rb index 6b8e780d5..2a8d4b748 100644 --- a/app/jobs/discarded_dossiers_deletion_job.rb +++ b/app/jobs/cron/discarded_dossiers_deletion_job.rb @@ -1,4 +1,4 @@ -class DiscardedDossiersDeletionJob < CronJob +class Cron::DiscardedDossiersDeletionJob < Cron::CronJob self.schedule_expression = "every day at 2 am" def perform(*args) diff --git a/app/jobs/discarded_procedures_deletion_job.rb b/app/jobs/cron/discarded_procedures_deletion_job.rb similarity index 79% rename from app/jobs/discarded_procedures_deletion_job.rb rename to app/jobs/cron/discarded_procedures_deletion_job.rb index 5361a422f..8f1a6b92d 100644 --- a/app/jobs/discarded_procedures_deletion_job.rb +++ b/app/jobs/cron/discarded_procedures_deletion_job.rb @@ -1,4 +1,4 @@ -class DiscardedProceduresDeletionJob < CronJob +class Cron::DiscardedProceduresDeletionJob < Cron::CronJob self.schedule_expression = "every day at 1 am" def perform(*args) diff --git a/app/jobs/expired_dossiers_deletion_job.rb b/app/jobs/cron/expired_dossiers_deletion_job.rb similarity index 80% rename from app/jobs/expired_dossiers_deletion_job.rb rename to app/jobs/cron/expired_dossiers_deletion_job.rb index 65c80d23d..565c66975 100644 --- a/app/jobs/expired_dossiers_deletion_job.rb +++ b/app/jobs/cron/expired_dossiers_deletion_job.rb @@ -1,4 +1,4 @@ -class ExpiredDossiersDeletionJob < CronJob +class Cron::ExpiredDossiersDeletionJob < Cron::CronJob self.schedule_expression = "every day at 7 am" def perform(*args) diff --git a/app/jobs/find_dubious_procedures_job.rb b/app/jobs/cron/find_dubious_procedures_job.rb similarity index 95% rename from app/jobs/find_dubious_procedures_job.rb rename to app/jobs/cron/find_dubious_procedures_job.rb index 13c9a91ab..d2ed23561 100644 --- a/app/jobs/find_dubious_procedures_job.rb +++ b/app/jobs/cron/find_dubious_procedures_job.rb @@ -1,4 +1,4 @@ -class FindDubiousProceduresJob < CronJob +class Cron::FindDubiousProceduresJob < Cron::CronJob self.schedule_expression = "every day at midnight" FORBIDDEN_KEYWORDS = [ diff --git a/app/jobs/instructeur_email_notification_job.rb b/app/jobs/cron/instructeur_email_notification_job.rb similarity index 72% rename from app/jobs/instructeur_email_notification_job.rb rename to app/jobs/cron/instructeur_email_notification_job.rb index 5b49576bf..a81354da8 100644 --- a/app/jobs/instructeur_email_notification_job.rb +++ b/app/jobs/cron/instructeur_email_notification_job.rb @@ -1,4 +1,4 @@ -class InstructeurEmailNotificationJob < CronJob +class Cron::InstructeurEmailNotificationJob < Cron::CronJob self.schedule_expression = "from monday through friday at 10 am" def perform(*args) diff --git a/app/jobs/notify_draft_not_submitted_job.rb b/app/jobs/cron/notify_draft_not_submitted_job.rb similarity index 71% rename from app/jobs/notify_draft_not_submitted_job.rb rename to app/jobs/cron/notify_draft_not_submitted_job.rb index 2fbfe382f..24100930a 100644 --- a/app/jobs/notify_draft_not_submitted_job.rb +++ b/app/jobs/cron/notify_draft_not_submitted_job.rb @@ -1,4 +1,4 @@ -class NotifyDraftNotSubmittedJob < CronJob +class Cron::NotifyDraftNotSubmittedJob < Cron::CronJob self.schedule_expression = "from monday through friday at 7 am" def perform(*args) diff --git a/app/jobs/operations_signature_job.rb b/app/jobs/cron/operations_signature_job.rb similarity index 89% rename from app/jobs/operations_signature_job.rb rename to app/jobs/cron/operations_signature_job.rb index 2ad62da43..605cea333 100644 --- a/app/jobs/operations_signature_job.rb +++ b/app/jobs/cron/operations_signature_job.rb @@ -1,4 +1,4 @@ -class OperationsSignatureJob < CronJob +class Cron::OperationsSignatureJob < Cron::CronJob self.schedule_expression = "every day at 6 am" def perform(*args) diff --git a/app/jobs/purge_stale_exports_job.rb b/app/jobs/cron/purge_stale_exports_job.rb similarity index 67% rename from app/jobs/purge_stale_exports_job.rb rename to app/jobs/cron/purge_stale_exports_job.rb index 1f3480752..5e0fbcf6c 100644 --- a/app/jobs/purge_stale_exports_job.rb +++ b/app/jobs/cron/purge_stale_exports_job.rb @@ -1,4 +1,4 @@ -class PurgeStaleExportsJob < CronJob +class Cron::PurgeStaleExportsJob < Cron::CronJob self.schedule_expression = "every 5 minutes" def perform diff --git a/app/jobs/purge_unattached_blobs_job.rb b/app/jobs/cron/purge_unattached_blobs_job.rb similarity index 80% rename from app/jobs/purge_unattached_blobs_job.rb rename to app/jobs/cron/purge_unattached_blobs_job.rb index 6ca57ba9f..fe0ec87a4 100644 --- a/app/jobs/purge_unattached_blobs_job.rb +++ b/app/jobs/cron/purge_unattached_blobs_job.rb @@ -1,4 +1,4 @@ -class PurgeUnattachedBlobsJob < CronJob +class Cron::PurgeUnattachedBlobsJob < Cron::CronJob self.schedule_expression = "every day at midnight" def perform(*args) diff --git a/app/jobs/update_administrateur_usage_statistics_job.rb b/app/jobs/cron/update_administrateur_usage_statistics_job.rb similarity index 68% rename from app/jobs/update_administrateur_usage_statistics_job.rb rename to app/jobs/cron/update_administrateur_usage_statistics_job.rb index d873ee362..f7f018411 100644 --- a/app/jobs/update_administrateur_usage_statistics_job.rb +++ b/app/jobs/cron/update_administrateur_usage_statistics_job.rb @@ -1,4 +1,4 @@ -class UpdateAdministrateurUsageStatisticsJob < CronJob +class Cron::UpdateAdministrateurUsageStatisticsJob < Cron::CronJob self.schedule_expression = "every day at 10 am" def perform diff --git a/app/jobs/update_stats_job.rb b/app/jobs/cron/update_stats_job.rb similarity index 69% rename from app/jobs/update_stats_job.rb rename to app/jobs/cron/update_stats_job.rb index b1202b67e..a5dcd2c43 100644 --- a/app/jobs/update_stats_job.rb +++ b/app/jobs/cron/update_stats_job.rb @@ -1,4 +1,4 @@ -class UpdateStatsJob < CronJob +class Cron::UpdateStatsJob < Cron::CronJob self.schedule_expression = "every 1 hour" def perform(*args) diff --git a/app/jobs/weekly_overview_job.rb b/app/jobs/cron/weekly_overview_job.rb similarity index 90% rename from app/jobs/weekly_overview_job.rb rename to app/jobs/cron/weekly_overview_job.rb index e1e17541f..bc009a1b4 100644 --- a/app/jobs/weekly_overview_job.rb +++ b/app/jobs/cron/weekly_overview_job.rb @@ -1,4 +1,4 @@ -class WeeklyOverviewJob < CronJob +class Cron::WeeklyOverviewJob < Cron::CronJob self.schedule_expression = "every monday at 7 am" def perform(*args) diff --git a/spec/jobs/administrateur_activate_before_expiration_job_spec.rb b/spec/jobs/cron/administrateur_activate_before_expiration_job_spec.rb similarity index 93% rename from spec/jobs/administrateur_activate_before_expiration_job_spec.rb rename to spec/jobs/cron/administrateur_activate_before_expiration_job_spec.rb index 504f8cef4..0f6334efb 100644 --- a/spec/jobs/administrateur_activate_before_expiration_job_spec.rb +++ b/spec/jobs/cron/administrateur_activate_before_expiration_job_spec.rb @@ -1,10 +1,10 @@ -RSpec.describe AdministrateurActivateBeforeExpirationJob, type: :job do +RSpec.describe Cron::AdministrateurActivateBeforeExpirationJob, type: :job do describe 'perform' do let(:administrateur) { create(:administrateur) } let(:user) { administrateur.user } let(:mailer_double) { double('mailer', deliver_later: true) } - subject { AdministrateurActivateBeforeExpirationJob.perform_now } + subject { Cron::AdministrateurActivateBeforeExpirationJob.perform_now } before do Timecop.freeze(Time.zone.local(2018, 03, 20)) diff --git a/spec/jobs/auto_archive_procedure_job_spec.rb b/spec/jobs/cron/auto_archive_procedure_job_spec.rb similarity index 96% rename from spec/jobs/auto_archive_procedure_job_spec.rb rename to spec/jobs/cron/auto_archive_procedure_job_spec.rb index 3f1600b6c..fd414482a 100644 --- a/spec/jobs/auto_archive_procedure_job_spec.rb +++ b/spec/jobs/cron/auto_archive_procedure_job_spec.rb @@ -1,10 +1,10 @@ -RSpec.describe AutoArchiveProcedureJob, type: :job do +RSpec.describe Cron::AutoArchiveProcedureJob, type: :job do let!(:procedure) { create(:procedure, :published, :with_instructeur, auto_archive_on: nil) } let!(:procedure_hier) { create(:procedure, :published, :with_instructeur, auto_archive_on: 1.day.ago.to_date) } let!(:procedure_aujourdhui) { create(:procedure, :published, :with_instructeur, auto_archive_on: Time.zone.today) } let!(:procedure_demain) { create(:procedure, :published, :with_instructeur, auto_archive_on: 1.day.from_now.to_date) } - subject { AutoArchiveProcedureJob.new.perform } + subject { Cron::AutoArchiveProcedureJob.new.perform } context "when procedures have no auto_archive_on" do before do diff --git a/spec/jobs/declarative_procedures_job_spec.rb b/spec/jobs/cron/declarative_procedures_job_spec.rb similarity index 96% rename from spec/jobs/declarative_procedures_job_spec.rb rename to spec/jobs/cron/declarative_procedures_job_spec.rb index 4a4238174..6b96939fe 100644 --- a/spec/jobs/declarative_procedures_job_spec.rb +++ b/spec/jobs/cron/declarative_procedures_job_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe DeclarativeProceduresJob, type: :job do +RSpec.describe Cron::DeclarativeProceduresJob, type: :job do describe "perform" do let(:date) { Time.utc(2017, 9, 1, 10, 5, 0) } let(:instruction_date) { date + 120 } @@ -20,7 +20,7 @@ RSpec.describe DeclarativeProceduresJob, type: :job do ] create(:attestation_template, procedure: procedure) - DeclarativeProceduresJob.new.perform + Cron::DeclarativeProceduresJob.new.perform dossiers.each(&:reload) end diff --git a/spec/jobs/find_dubious_procedures_job_spec.rb b/spec/jobs/cron/find_dubious_procedures_job_spec.rb similarity index 94% rename from spec/jobs/find_dubious_procedures_job_spec.rb rename to spec/jobs/cron/find_dubious_procedures_job_spec.rb index acbc8df52..cbacacf82 100644 --- a/spec/jobs/find_dubious_procedures_job_spec.rb +++ b/spec/jobs/cron/find_dubious_procedures_job_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe FindDubiousProceduresJob, type: :job do +RSpec.describe Cron::FindDubiousProceduresJob, type: :job do describe 'perform' do let(:mailer_double) { double('mailer', deliver_later: true) } let(:procedure) { create(:procedure, types_de_champ: tdcs) } @@ -11,7 +11,7 @@ RSpec.describe FindDubiousProceduresJob, type: :job do @dubious_procedures_args = arg end.and_return(mailer_double) - FindDubiousProceduresJob.new.perform + Cron::FindDubiousProceduresJob.new.perform end context 'with suspicious champs' do diff --git a/spec/jobs/weekly_overview_job_spec.rb b/spec/jobs/cron/weekly_overview_job_spec.rb similarity index 87% rename from spec/jobs/weekly_overview_job_spec.rb rename to spec/jobs/cron/weekly_overview_job_spec.rb index 3aa7a44e2..df62333d9 100644 --- a/spec/jobs/weekly_overview_job_spec.rb +++ b/spec/jobs/cron/weekly_overview_job_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe WeeklyOverviewJob, type: :job do +RSpec.describe Cron::WeeklyOverviewJob, type: :job do describe 'perform' do let!(:instructeur) { create(:instructeur) } let(:overview) { double('overview') } @@ -16,7 +16,7 @@ RSpec.describe WeeklyOverviewJob, type: :job do before do expect_any_instance_of(Instructeur).to receive(:last_week_overview).and_return(overview) allow(InstructeurMailer).to receive(:last_week_overview).and_return(mailer_double) - WeeklyOverviewJob.new.perform + Cron::WeeklyOverviewJob.new.perform end it { expect(InstructeurMailer).to have_received(:last_week_overview).with(instructeur) } @@ -27,7 +27,7 @@ RSpec.describe WeeklyOverviewJob, type: :job do before do expect_any_instance_of(Instructeur).to receive(:last_week_overview).and_return(nil) allow(InstructeurMailer).to receive(:last_week_overview) - WeeklyOverviewJob.new.perform + Cron::WeeklyOverviewJob.new.perform end it { expect(InstructeurMailer).not_to have_received(:last_week_overview) } @@ -37,7 +37,7 @@ RSpec.describe WeeklyOverviewJob, type: :job do context 'if the feature is disabled' do before do allow(Instructeur).to receive(:all) - WeeklyOverviewJob.new.perform + Cron::WeeklyOverviewJob.new.perform end it { expect(Instructeur).not_to receive(:all) } diff --git a/spec/models/instructeur_spec.rb b/spec/models/instructeur_spec.rb index 717b6fccd..37dbfa3dc 100644 --- a/spec/models/instructeur_spec.rb +++ b/spec/models/instructeur_spec.rb @@ -455,7 +455,7 @@ describe Instructeur, type: :model do before do procedure_to_assign.update(declarative_with_state: "en_instruction") - DeclarativeProceduresJob.new.perform + Cron::DeclarativeProceduresJob.new.perform dossier.reload end @@ -480,7 +480,7 @@ describe Instructeur, type: :model do before do procedure_to_assign.update(declarative_with_state: "accepte") - DeclarativeProceduresJob.new.perform + Cron::DeclarativeProceduresJob.new.perform dossier.reload end @@ -497,7 +497,7 @@ describe Instructeur, type: :model do before do procedure_to_assign.update(declarative_with_state: "accepte") - DeclarativeProceduresJob.new.perform + Cron::DeclarativeProceduresJob.new.perform dossier.traitements.last.update(processed_at: Time.zone.yesterday.beginning_of_day) dossier.reload end diff --git a/spec/services/notification_service_spec.rb b/spec/services/notification_service_spec.rb index 59266eab2..1f1b858c3 100644 --- a/spec/services/notification_service_spec.rb +++ b/spec/services/notification_service_spec.rb @@ -51,7 +51,7 @@ describe NotificationService do let!(:dossier) { create(:dossier, :en_construction, procedure: procedure) } before do procedure.update(declarative_with_state: "en_instruction") - DeclarativeProceduresJob.new.perform + Cron::DeclarativeProceduresJob.new.perform dossier.reload end @@ -65,7 +65,7 @@ describe NotificationService do let!(:dossier) { create(:dossier, :en_construction, procedure: procedure) } before do procedure.update(declarative_with_state: "accepte") - DeclarativeProceduresJob.new.perform + Cron::DeclarativeProceduresJob.new.perform dossier.traitements.last.update!(processed_at: Time.zone.yesterday.beginning_of_day) dossier.reload end @@ -80,7 +80,7 @@ describe NotificationService do let!(:dossier) { create(:dossier, :en_construction, procedure: procedure) } before do procedure.update(declarative_with_state: "accepte") - DeclarativeProceduresJob.new.perform + Cron::DeclarativeProceduresJob.new.perform dossier.reload end