Moved to new event buffer api.

This commit is contained in:
Martin Edenhofer 2016-04-14 01:50:22 +02:00
parent ed5b058d6e
commit ef64d1e1d7
2 changed files with 43 additions and 34 deletions

View file

@ -12,10 +12,10 @@ class Observer::Ticket::Notification < ActiveRecord::Observer
return if Setting.get('import_mode')
# get buffer
list = EventBuffer.list
list = EventBuffer.list('notification')
# reset buffer
EventBuffer.reset
EventBuffer.reset('notification')
via_web = false
if ENV['RACK_ENV'] || Rails.configuration.webserver_is_active
@ -36,17 +36,29 @@ class Observer::Ticket::Notification < ActiveRecord::Observer
result = get_uniq_changes(events)
result = {
:1 => {
:type => 'create',
:ticket_id => 123,
:article_id => 123,
1 => {
type: 'create',
ticket_id: 123,
article_id: 123,
},
:9 = {
:type => 'update',
:ticket_id => 123,
:changes => {
:attribute1 => [before,now],
:attribute2 => [before,now],
9 => {
type: 'update',
ticket_id: 123,
changes: {
attribute1: [before, now],
attribute2: [before, now],
}
},
}
result = {
9 => {
type: 'update',
ticket_id: 123,
article_id: 123,
changes: {
attribute1: [before, now],
attribute2: [before, now],
}
},
}
@ -124,7 +136,7 @@ class Observer::Ticket::Notification < ActiveRecord::Observer
data: record,
id: record.id,
}
EventBuffer.add(e)
EventBuffer.add('notification', e)
end
def before_update(record)
@ -160,18 +172,7 @@ class Observer::Ticket::Notification < ActiveRecord::Observer
changes: real_changes,
id: record.id,
}
EventBuffer.add(e)
EventBuffer.add('notification', e)
end
def after_update(_record)
# return if we run import mode
return if Setting.get('import_mode')
# Rails.logger.info 'after_update'
# Rails.logger.info record.inspect
# Rails.logger.info '-----'
# Rails.logger.info @a.inspect
# AuditTrail.new(record, "UPDATED")
end
end

View file

@ -1,18 +1,26 @@
module EventBuffer
def self.list
Thread.current[:event_buffer] || []
end
def self.add(item)
def self.list(key)
if !Thread.current[:event_buffer]
Thread.current[:event_buffer] = []
Thread.current[:event_buffer] = {}
end
Thread.current[:event_buffer].push item
Thread.current[:event_buffer][key] || []
end
def self.reset
Thread.current[:event_buffer] = []
def self.add(key, item)
if !Thread.current[:event_buffer]
Thread.current[:event_buffer] = {}
end
if !Thread.current[:event_buffer][key]
Thread.current[:event_buffer][key] = []
end
Thread.current[:event_buffer][key].push item
end
def self.reset(key)
return if !Thread.current[:event_buffer]
return if !Thread.current[:event_buffer][key]
Thread.current[:event_buffer][key] = []
end
end