Moved to background job for escalation recalculation work.
This commit is contained in:
parent
13d15b1f7d
commit
e7f93ce103
6 changed files with 98 additions and 25 deletions
44
app/models/observer/sla/ticket_rebuild_escalation.rb
Normal file
44
app/models/observer/sla/ticket_rebuild_escalation.rb
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
|
||||||
|
|
||||||
|
class Observer::Sla::TicketRebuildEscalation < ActiveRecord::Observer
|
||||||
|
observe 'sla'
|
||||||
|
|
||||||
|
def after_create(record)
|
||||||
|
_rebuild(record)
|
||||||
|
end
|
||||||
|
|
||||||
|
def after_update(record)
|
||||||
|
_check(record)
|
||||||
|
end
|
||||||
|
|
||||||
|
def after_delete(record)
|
||||||
|
_rebuild(record)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def _rebuild(record)
|
||||||
|
Cache.delete('SLA::List::Active')
|
||||||
|
|
||||||
|
# send background job
|
||||||
|
Delayed::Job.enqueue( Observer::Sla::TicketRebuildEscalation::BackgroundJob.new(record.id) )
|
||||||
|
end
|
||||||
|
|
||||||
|
def _check(record)
|
||||||
|
|
||||||
|
# return if we run import mode
|
||||||
|
return if Setting.get('import_mode') && !Setting.get('import_ignore_sla')
|
||||||
|
|
||||||
|
# check if condition has changed
|
||||||
|
changed = false
|
||||||
|
%w(condition calendar_id first_response_time update_time solution_time).each {|item|
|
||||||
|
next if !record.changes[item]
|
||||||
|
next if record.changes[item][0] == record.changes[item][1]
|
||||||
|
changed = true
|
||||||
|
}
|
||||||
|
return if !changed
|
||||||
|
|
||||||
|
_rebuild(record)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -0,0 +1,9 @@
|
||||||
|
class Observer::Sla::TicketRebuildEscalation::BackgroundJob
|
||||||
|
def initialize(_sla_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
def perform
|
||||||
|
Cache.delete('SLA::List::Active')
|
||||||
|
Ticket::Escalation.rebuild_all
|
||||||
|
end
|
||||||
|
end
|
|
@ -4,17 +4,5 @@ class Sla < ApplicationModel
|
||||||
store :condition
|
store :condition
|
||||||
store :data
|
store :data
|
||||||
validates :name, presence: true
|
validates :name, presence: true
|
||||||
|
|
||||||
belongs_to :calendar
|
belongs_to :calendar
|
||||||
|
|
||||||
after_create :escalation_calculation_rebuild
|
|
||||||
after_update :escalation_calculation_rebuild
|
|
||||||
after_destroy :escalation_calculation_rebuild
|
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def escalation_calculation_rebuild
|
|
||||||
Cache.delete( 'SLA::List::Active' )
|
|
||||||
Ticket::Escalation.rebuild_all
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -41,7 +41,8 @@ module Zammad
|
||||||
'observer::_user::_ref_object_touch',
|
'observer::_user::_ref_object_touch',
|
||||||
'observer::_user::_ticket_organization',
|
'observer::_user::_ticket_organization',
|
||||||
'observer::_user::_geo',
|
'observer::_user::_geo',
|
||||||
'observer::_organization::_ref_object_touch'
|
'observer::_organization::_ref_object_touch',
|
||||||
|
'observer::_sla::_ticket_rebuild_escalation'
|
||||||
|
|
||||||
# REST api path
|
# REST api path
|
||||||
config.api_path = '/api/v1'
|
config.api_path = '/api/v1'
|
||||||
|
|
|
@ -64,6 +64,24 @@ class TicketSlaTest < ActiveSupport::TestCase
|
||||||
created_by_id: 1,
|
created_by_id: 1,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
sla = Sla.create_or_update(
|
||||||
|
name: 'test sla 1',
|
||||||
|
condition: {},
|
||||||
|
first_response_time: 60,
|
||||||
|
update_time: 180,
|
||||||
|
solution_time: 240,
|
||||||
|
calendar_id: calendar1.id,
|
||||||
|
updated_by_id: 1,
|
||||||
|
created_by_id: 1,
|
||||||
|
)
|
||||||
|
#puts Delayed::Job.all.inspect
|
||||||
|
Delayed::Worker.new.work_off
|
||||||
|
ticket = Ticket.find(ticket.id)
|
||||||
|
assert_equal( ticket.escalation_time.gmtime.to_s, '2013-03-21 10:30:00 UTC', 'ticket.escalation_time verify 1' )
|
||||||
|
assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-03-21 10:30:00 UTC', 'ticket.first_response_escal_date verify 1' )
|
||||||
|
assert_equal( ticket.update_time_escal_date.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.update_time_escal_date verify 1' )
|
||||||
|
assert_equal( ticket.close_time_escal_date.gmtime.to_s, '2013-03-21 13:30:00 UTC', 'ticket.close_time_escal_date verify 1' )
|
||||||
|
|
||||||
sla = Sla.create_or_update(
|
sla = Sla.create_or_update(
|
||||||
name: 'test sla 1',
|
name: 'test sla 1',
|
||||||
condition: {},
|
condition: {},
|
||||||
|
@ -74,6 +92,8 @@ class TicketSlaTest < ActiveSupport::TestCase
|
||||||
updated_by_id: 1,
|
updated_by_id: 1,
|
||||||
created_by_id: 1,
|
created_by_id: 1,
|
||||||
)
|
)
|
||||||
|
#puts Delayed::Job.all.inspect
|
||||||
|
Delayed::Worker.new.work_off
|
||||||
ticket = Ticket.find(ticket.id)
|
ticket = Ticket.find(ticket.id)
|
||||||
assert_equal( ticket.escalation_time.gmtime.to_s, '2013-03-21 11:30:00 UTC', 'ticket.escalation_time verify 1' )
|
assert_equal( ticket.escalation_time.gmtime.to_s, '2013-03-21 11:30:00 UTC', 'ticket.escalation_time verify 1' )
|
||||||
assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-03-21 11:30:00 UTC', 'ticket.first_response_escal_date verify 1' )
|
assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-03-21 11:30:00 UTC', 'ticket.first_response_escal_date verify 1' )
|
||||||
|
@ -135,6 +155,8 @@ class TicketSlaTest < ActiveSupport::TestCase
|
||||||
updated_by_id: 1,
|
updated_by_id: 1,
|
||||||
created_by_id: 1,
|
created_by_id: 1,
|
||||||
)
|
)
|
||||||
|
#puts Delayed::Job.all.inspect
|
||||||
|
Delayed::Worker.new.work_off
|
||||||
ticket = Ticket.find(ticket.id)
|
ticket = Ticket.find(ticket.id)
|
||||||
assert_equal( ticket.escalation_time.gmtime.to_s, '2013-03-21 10:30:00 UTC', 'ticket.escalation_time verify 2' )
|
assert_equal( ticket.escalation_time.gmtime.to_s, '2013-03-21 10:30:00 UTC', 'ticket.escalation_time verify 2' )
|
||||||
assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-03-21 10:30:00 UTC', 'ticket.first_response_escal_date verify 2' )
|
assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-03-21 10:30:00 UTC', 'ticket.first_response_escal_date verify 2' )
|
||||||
|
@ -579,6 +601,8 @@ class TicketSlaTest < ActiveSupport::TestCase
|
||||||
updated_by_id: 1,
|
updated_by_id: 1,
|
||||||
created_by_id: 1,
|
created_by_id: 1,
|
||||||
)
|
)
|
||||||
|
#puts Delayed::Job.all.inspect
|
||||||
|
Delayed::Worker.new.work_off
|
||||||
ticket = Ticket.find(ticket.id)
|
ticket = Ticket.find(ticket.id)
|
||||||
assert_equal( ticket.escalation_time.gmtime.to_s, '2013-03-21 11:30:00 UTC', 'ticket.escalation_time verify 1' )
|
assert_equal( ticket.escalation_time.gmtime.to_s, '2013-03-21 11:30:00 UTC', 'ticket.escalation_time verify 1' )
|
||||||
assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-03-21 11:30:00 UTC', 'ticket.first_response_escal_date verify 1' )
|
assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-03-21 11:30:00 UTC', 'ticket.first_response_escal_date verify 1' )
|
||||||
|
@ -667,7 +691,8 @@ class TicketSlaTest < ActiveSupport::TestCase
|
||||||
updated_by_id: 1,
|
updated_by_id: 1,
|
||||||
created_by_id: 1,
|
created_by_id: 1,
|
||||||
)
|
)
|
||||||
|
#puts Delayed::Job.all.inspect
|
||||||
|
Delayed::Worker.new.work_off
|
||||||
ticket = Ticket.find(ticket.id)
|
ticket = Ticket.find(ticket.id)
|
||||||
assert_equal( ticket.escalation_time.gmtime.to_s, '2013-10-21 11:30:00 UTC', 'ticket.escalation_time verify 1' )
|
assert_equal( ticket.escalation_time.gmtime.to_s, '2013-10-21 11:30:00 UTC', 'ticket.escalation_time verify 1' )
|
||||||
assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-10-21 11:30:00 UTC', 'ticket.first_response_escal_date verify 1' )
|
assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-10-21 11:30:00 UTC', 'ticket.first_response_escal_date verify 1' )
|
||||||
|
@ -705,6 +730,8 @@ class TicketSlaTest < ActiveSupport::TestCase
|
||||||
updated_by_id: 1,
|
updated_by_id: 1,
|
||||||
created_by_id: 1,
|
created_by_id: 1,
|
||||||
)
|
)
|
||||||
|
#puts Delayed::Job.all.inspect
|
||||||
|
Delayed::Worker.new.work_off
|
||||||
ticket = Ticket.find(ticket.id)
|
ticket = Ticket.find(ticket.id)
|
||||||
assert_equal( ticket.escalation_time.gmtime.to_s, '2013-10-21 08:00:00 UTC', 'ticket.escalation_time verify 1' )
|
assert_equal( ticket.escalation_time.gmtime.to_s, '2013-10-21 08:00:00 UTC', 'ticket.escalation_time verify 1' )
|
||||||
assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-10-21 08:00:00 UTC', 'ticket.first_response_escal_date verify 1' )
|
assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-10-21 08:00:00 UTC', 'ticket.first_response_escal_date verify 1' )
|
||||||
|
@ -858,7 +885,8 @@ class TicketSlaTest < ActiveSupport::TestCase
|
||||||
updated_by_id: 1,
|
updated_by_id: 1,
|
||||||
created_by_id: 1,
|
created_by_id: 1,
|
||||||
)
|
)
|
||||||
|
#puts Delayed::Job.all.inspect
|
||||||
|
Delayed::Worker.new.work_off
|
||||||
ticket = Ticket.find(ticket.id)
|
ticket = Ticket.find(ticket.id)
|
||||||
assert_equal( ticket.escalation_time.gmtime.to_s, '2013-06-04 13:30:00 UTC', 'ticket.escalation_time verify 1' )
|
assert_equal( ticket.escalation_time.gmtime.to_s, '2013-06-04 13:30:00 UTC', 'ticket.escalation_time verify 1' )
|
||||||
assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-06-04 11:30:00 UTC', 'ticket.first_response_escal_date verify 1' )
|
assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-06-04 11:30:00 UTC', 'ticket.first_response_escal_date verify 1' )
|
||||||
|
@ -954,8 +982,9 @@ class TicketSlaTest < ActiveSupport::TestCase
|
||||||
updated_by_id: 1,
|
updated_by_id: 1,
|
||||||
created_by_id: 1,
|
created_by_id: 1,
|
||||||
)
|
)
|
||||||
|
#puts Delayed::Job.all.inspect
|
||||||
|
Delayed::Worker.new.work_off
|
||||||
ticket = Ticket.find(ticket.id)
|
ticket = Ticket.find(ticket.id)
|
||||||
|
|
||||||
assert_equal( ticket.escalation_time, nil, 'ticket.escalation_time verify 1' )
|
assert_equal( ticket.escalation_time, nil, 'ticket.escalation_time verify 1' )
|
||||||
assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-06-04 13:00:00 UTC', 'ticket.first_response_escal_date verify 1' )
|
assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-06-04 13:00:00 UTC', 'ticket.first_response_escal_date verify 1' )
|
||||||
assert_equal( ticket.first_response_in_min, nil, 'ticket.first_response_in_min verify 3' )
|
assert_equal( ticket.first_response_in_min, nil, 'ticket.first_response_in_min verify 3' )
|
||||||
|
@ -1081,8 +1110,9 @@ class TicketSlaTest < ActiveSupport::TestCase
|
||||||
updated_by_id: 1,
|
updated_by_id: 1,
|
||||||
created_by_id: 1,
|
created_by_id: 1,
|
||||||
)
|
)
|
||||||
|
#puts Delayed::Job.all.inspect
|
||||||
|
Delayed::Worker.new.work_off
|
||||||
ticket = Ticket.find(ticket.id)
|
ticket = Ticket.find(ticket.id)
|
||||||
|
|
||||||
assert_equal( ticket.escalation_time, nil, 'ticket.escalation_time verify 1' )
|
assert_equal( ticket.escalation_time, nil, 'ticket.escalation_time verify 1' )
|
||||||
assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-06-04 12:30:00 UTC', 'ticket.first_response_escal_date verify 1' )
|
assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-06-04 12:30:00 UTC', 'ticket.first_response_escal_date verify 1' )
|
||||||
assert_equal( ticket.first_response_in_min, nil, 'ticket.first_response_in_min verify 3' )
|
assert_equal( ticket.first_response_in_min, nil, 'ticket.first_response_in_min verify 3' )
|
||||||
|
@ -1224,8 +1254,9 @@ class TicketSlaTest < ActiveSupport::TestCase
|
||||||
updated_by_id: 1,
|
updated_by_id: 1,
|
||||||
created_by_id: 1,
|
created_by_id: 1,
|
||||||
)
|
)
|
||||||
|
#puts Delayed::Job.all.inspect
|
||||||
|
Delayed::Worker.new.work_off
|
||||||
ticket = Ticket.find(ticket.id)
|
ticket = Ticket.find(ticket.id)
|
||||||
|
|
||||||
assert_equal( ticket.escalation_time, nil, 'ticket.escalation_time verify 1' )
|
assert_equal( ticket.escalation_time, nil, 'ticket.escalation_time verify 1' )
|
||||||
assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-06-04 12:30:00 UTC', 'ticket.first_response_escal_date verify 1' )
|
assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-06-04 12:30:00 UTC', 'ticket.first_response_escal_date verify 1' )
|
||||||
assert_equal( ticket.first_response_in_min, nil, 'ticket.first_response_in_min verify 3' )
|
assert_equal( ticket.first_response_in_min, nil, 'ticket.first_response_in_min verify 3' )
|
||||||
|
|
Loading…
Reference in a new issue