ticket_online_notification_seen_job.rb 776 B

12345678910111213141516171819202122232425262728
  1. class TicketOnlineNotificationSeenJob < ApplicationJob
  2. include HasActiveJobLock
  3. def lock_key
  4. # "TicketOnlineNotificationSeenJob/23/42"
  5. "#{self.class.name}/#{arguments[0]}/#{arguments[1]}"
  6. end
  7. def perform(ticket_id, user_id)
  8. user_id = user_id || 1
  9. # set all online notifications to seen
  10. Transaction.execute do
  11. ticket = Ticket.lookup(id: ticket_id)
  12. OnlineNotification.list_by_object('Ticket', ticket_id).each do |notification|
  13. next if notification.seen
  14. seen = ticket.online_notification_seen_state(notification.user_id)
  15. next if !seen
  16. next if seen == notification.seen
  17. notification.seen = true
  18. notification.updated_by_id = user_id
  19. notification.save!
  20. end
  21. end
  22. end
  23. end