Moved to background jobs.
This commit is contained in:
parent
cf2ce642ef
commit
e4896fbb7e
5 changed files with 51 additions and 31 deletions
|
@ -37,6 +37,5 @@ class Observer::Ticket::EscalationCalculation < ActiveRecord::Observer
|
|||
record.callback_loop = true
|
||||
record.escalation_calculation
|
||||
record.callback_loop = false
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -22,6 +22,7 @@ class Observer::Ticket::OnlineNotificationSeen < ActiveRecord::Observer
|
|||
return true if !record.online_notification_seen_state
|
||||
|
||||
# set all online notifications to seen
|
||||
OnlineNotification.seen_by_object( 'Ticket', record.id )
|
||||
# send background job
|
||||
Delayed::Job.enqueue( Observer::Ticket::UserTicketCounter::BackgroundJob.new( record.id ) )
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
class Observer::Ticket::OnlineNotificationSeen::BackgroundJob
|
||||
def initialize(id)
|
||||
@ticket_id = id
|
||||
end
|
||||
def perform
|
||||
|
||||
# set all online notifications to seen
|
||||
OnlineNotification.seen_by_object( 'Ticket', @ticket_id )
|
||||
end
|
||||
end
|
|
@ -17,35 +17,8 @@ class Observer::Ticket::UserTicketCounter < ActiveRecord::Observer
|
|||
|
||||
return if !record.customer_id
|
||||
|
||||
# open ticket count
|
||||
state_open = Ticket::State.by_category( 'open' )
|
||||
tickets_open = Ticket.where(
|
||||
customer_id: record.customer_id,
|
||||
state_id: state_open,
|
||||
).count()
|
||||
|
||||
# closed ticket count
|
||||
state_closed = Ticket::State.by_category( 'closed' )
|
||||
tickets_closed = Ticket.where(
|
||||
customer_id: record.customer_id,
|
||||
state_id: state_closed,
|
||||
).count()
|
||||
|
||||
# check if update is needed
|
||||
customer = User.lookup( id: record.customer_id )
|
||||
need_update = false
|
||||
if customer[:preferences][:tickets_open] != tickets_open
|
||||
need_update = true
|
||||
customer[:preferences][:tickets_open] = tickets_open
|
||||
end
|
||||
if customer[:preferences][:tickets_closed] != tickets_closed
|
||||
need_update = true
|
||||
customer[:preferences][:tickets_closed] = tickets_closed
|
||||
end
|
||||
|
||||
return if !need_update
|
||||
|
||||
customer.save
|
||||
# send background job
|
||||
Delayed::Job.enqueue( Observer::Ticket::UserTicketCounter::BackgroundJob.new( record.customer_id ) )
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
class Observer::Ticket::UserTicketCounter::BackgroundJob
|
||||
def initialize(id)
|
||||
@customer_id = id
|
||||
end
|
||||
def perform
|
||||
|
||||
# open ticket count
|
||||
state_open = Ticket::State.by_category( 'open' )
|
||||
tickets_open = Ticket.where(
|
||||
customer_id: @customer_id,
|
||||
state_id: state_open,
|
||||
).count()
|
||||
|
||||
# closed ticket count
|
||||
state_closed = Ticket::State.by_category( 'closed' )
|
||||
tickets_closed = Ticket.where(
|
||||
customer_id: @customer_id,
|
||||
state_id: state_closed,
|
||||
).count()
|
||||
|
||||
# check if update is needed
|
||||
customer = User.lookup( id: @customer_id )
|
||||
need_update = false
|
||||
if customer[:preferences][:tickets_open] != tickets_open
|
||||
need_update = true
|
||||
customer[:preferences][:tickets_open] = tickets_open
|
||||
end
|
||||
if customer[:preferences][:tickets_closed] != tickets_closed
|
||||
need_update = true
|
||||
customer[:preferences][:tickets_closed] = tickets_closed
|
||||
end
|
||||
|
||||
return if !need_update
|
||||
|
||||
customer.save
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue