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') return if Setting.get('import_mode')
# get buffer # get buffer
list = EventBuffer.list list = EventBuffer.list('notification')
# reset buffer # reset buffer
EventBuffer.reset EventBuffer.reset('notification')
via_web = false via_web = false
if ENV['RACK_ENV'] || Rails.configuration.webserver_is_active 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 = get_uniq_changes(events)
result = { result = {
:1 => { 1 => {
:type => 'create', type: 'create',
:ticket_id => 123, ticket_id: 123,
:article_id => 123, article_id: 123,
}, },
:9 = { 9 => {
:type => 'update', type: 'update',
:ticket_id => 123, ticket_id: 123,
:changes => { changes: {
:attribute1 => [before,now], attribute1: [before, now],
:attribute2 => [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, data: record,
id: record.id, id: record.id,
} }
EventBuffer.add(e) EventBuffer.add('notification', e)
end end
def before_update(record) def before_update(record)
@ -160,18 +172,7 @@ class Observer::Ticket::Notification < ActiveRecord::Observer
changes: real_changes, changes: real_changes,
id: record.id, id: record.id,
} }
EventBuffer.add(e) EventBuffer.add('notification', e)
end 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 end

View file

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