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