Fixed issue #2574 - Every night tickets are updated (system need to use SLAs).
This commit is contained in:
parent
1fd0e82254
commit
dd1a6c30fc
3 changed files with 34 additions and 8 deletions
|
@ -166,9 +166,7 @@ returns
|
||||||
end
|
end
|
||||||
|
|
||||||
# sync with public_holidays
|
# sync with public_holidays
|
||||||
if !public_holidays
|
self.public_holidays ||= {}
|
||||||
self.public_holidays = {}
|
|
||||||
end
|
|
||||||
|
|
||||||
# remove old ical entries if feed has changed
|
# remove old ical entries if feed has changed
|
||||||
public_holidays.each do |day, meta|
|
public_holidays.each do |day, meta|
|
||||||
|
@ -180,13 +178,14 @@ returns
|
||||||
|
|
||||||
# sync new ical feed dates
|
# sync new ical feed dates
|
||||||
events.each do |day, summary|
|
events.each do |day, summary|
|
||||||
if !public_holidays[day]
|
public_holidays[day] ||= {}
|
||||||
public_holidays[day] = {}
|
|
||||||
end
|
|
||||||
|
|
||||||
# ignore if already added or changed
|
# ignore if already added or changed
|
||||||
next if public_holidays[day].key?('active')
|
next if public_holidays[day].key?('active')
|
||||||
|
|
||||||
|
# entry already exists
|
||||||
|
next if summary == public_holidays[day][:summary]
|
||||||
|
|
||||||
# create new entry
|
# create new entry
|
||||||
public_holidays[day] = {
|
public_holidays[day] = {
|
||||||
active: true,
|
active: true,
|
||||||
|
|
|
@ -4,6 +4,8 @@ class Observer::Sla::TicketRebuildEscalation < ActiveRecord::Observer
|
||||||
observe 'sla', 'calendar'
|
observe 'sla', 'calendar'
|
||||||
|
|
||||||
def after_commit(record)
|
def after_commit(record)
|
||||||
|
return if _check(record)
|
||||||
|
|
||||||
_rebuild(record)
|
_rebuild(record)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -37,7 +39,7 @@ class Observer::Sla::TicketRebuildEscalation < ActiveRecord::Observer
|
||||||
end
|
end
|
||||||
return true if !changed
|
return true if !changed
|
||||||
|
|
||||||
_rebuild(record)
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -86,7 +86,7 @@ RSpec.describe Calendar, type: :model do
|
||||||
|
|
||||||
describe '#sync' do
|
describe '#sync' do
|
||||||
subject(:calendar) do
|
subject(:calendar) do
|
||||||
create(:calendar, ical_url: Rails.root.join('test', 'data', 'calendar', 'calendar1.ics'))
|
create(:calendar, ical_url: Rails.root.join('test', 'data', 'calendar', 'calendar1.ics'), default: false)
|
||||||
end
|
end
|
||||||
|
|
||||||
before { travel_to Time.zone.parse('2017-08-24T01:04:44Z0') }
|
before { travel_to Time.zone.parse('2017-08-24T01:04:44Z0') }
|
||||||
|
@ -105,6 +105,27 @@ RSpec.describe Calendar, type: :model do
|
||||||
expect { calendar.sync }
|
expect { calendar.sync }
|
||||||
.not_to change { calendar.public_holidays }
|
.not_to change { calendar.public_holidays }
|
||||||
end
|
end
|
||||||
|
it 'does not create a background job for escalation rebuild' do
|
||||||
|
calendar # create and sync (1 inital background job is created)
|
||||||
|
expect { calendar.sync } # a second sync right after calendar create
|
||||||
|
.to not_change { Delayed::Job.count }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'and current date has changed but neither public_holidays nor iCal URL have changed (past cache expiry)' do
|
||||||
|
before do
|
||||||
|
calendar # create and sync
|
||||||
|
travel 2.days
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'is idempotent' do
|
||||||
|
expect { calendar.sync }
|
||||||
|
.not_to change { calendar.public_holidays }
|
||||||
|
end
|
||||||
|
it 'does not create a background job for escalation rebuild' do
|
||||||
|
expect { calendar.sync }
|
||||||
|
.not_to change { Delayed::Job.count }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'and current date has changed (past cache expiry)' do
|
context 'and current date has changed (past cache expiry)' do
|
||||||
|
@ -122,6 +143,10 @@ RSpec.describe Calendar, type: :model do
|
||||||
'2020-12-24' => { 'active' => true, 'summary' => 'Christmas1', 'feed' => Digest::MD5.hexdigest(calendar.ical_url) },
|
'2020-12-24' => { 'active' => true, 'summary' => 'Christmas1', 'feed' => Digest::MD5.hexdigest(calendar.ical_url) },
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'does create a background job for escalation rebuild' do
|
||||||
|
expect { calendar.sync }.to change { Delayed::Job.count }.by(1)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'and iCal URL has changed' do
|
context 'and iCal URL has changed' do
|
||||||
|
|
Loading…
Reference in a new issue