From b370975a014a2a72240cd243dc5f429dc1550839 Mon Sep 17 00:00:00 2001 From: Rolf Schmidt Date: Thu, 24 Jan 2019 16:00:59 +0100 Subject: [PATCH] Refactoring: Migrated Observer::Sla::TicketRebuildEscalation::BackgroundJob from Delayed::Job to Active Job. --- app/jobs/sla_ticket_rebuild_escalation_job.rb | 6 ++++++ app/models/observer/sla/ticket_rebuild_escalation.rb | 2 +- .../sla/ticket_rebuild_escalation/background_job.rb | 8 -------- spec/jobs/sla_ticket_rebuild_escalation_job_spec.rb | 12 ++++++++++++ 4 files changed, 19 insertions(+), 9 deletions(-) create mode 100644 app/jobs/sla_ticket_rebuild_escalation_job.rb delete mode 100644 app/models/observer/sla/ticket_rebuild_escalation/background_job.rb create mode 100644 spec/jobs/sla_ticket_rebuild_escalation_job_spec.rb diff --git a/app/jobs/sla_ticket_rebuild_escalation_job.rb b/app/jobs/sla_ticket_rebuild_escalation_job.rb new file mode 100644 index 000000000..cb8f7e997 --- /dev/null +++ b/app/jobs/sla_ticket_rebuild_escalation_job.rb @@ -0,0 +1,6 @@ +class SlaTicketRebuildEscalationJob < ApplicationJob + def perform(_sla_id) + Cache.delete('SLA::List::Active') + Ticket::Escalation.rebuild_all + end +end diff --git a/app/models/observer/sla/ticket_rebuild_escalation.rb b/app/models/observer/sla/ticket_rebuild_escalation.rb index eac8a6fea..1100d023b 100644 --- a/app/models/observer/sla/ticket_rebuild_escalation.rb +++ b/app/models/observer/sla/ticket_rebuild_escalation.rb @@ -13,7 +13,7 @@ class Observer::Sla::TicketRebuildEscalation < ActiveRecord::Observer Cache.delete('SLA::List::Active') # send background job - Delayed::Job.enqueue( Observer::Sla::TicketRebuildEscalation::BackgroundJob.new(record.id) ) + SlaTicketRebuildEscalationJob.perform_later(record.id) end def _check(record) diff --git a/app/models/observer/sla/ticket_rebuild_escalation/background_job.rb b/app/models/observer/sla/ticket_rebuild_escalation/background_job.rb deleted file mode 100644 index 002d7ab2d..000000000 --- a/app/models/observer/sla/ticket_rebuild_escalation/background_job.rb +++ /dev/null @@ -1,8 +0,0 @@ -class Observer::Sla::TicketRebuildEscalation::BackgroundJob - def initialize(_sla_id); end - - def perform - Cache.delete('SLA::List::Active') - Ticket::Escalation.rebuild_all - end -end diff --git a/spec/jobs/sla_ticket_rebuild_escalation_job_spec.rb b/spec/jobs/sla_ticket_rebuild_escalation_job_spec.rb new file mode 100644 index 000000000..5e73b554a --- /dev/null +++ b/spec/jobs/sla_ticket_rebuild_escalation_job_spec.rb @@ -0,0 +1,12 @@ +require 'rails_helper' + +RSpec.describe SlaTicketRebuildEscalationJob, type: :job do + + it 'executes the job' do + sla = create(:sla) + + expect(Cache).to receive(:delete).with('SLA::List::Active') + expect(Ticket::Escalation).to receive(:rebuild_all) + described_class.perform_now(sla.id) + end +end