ticket_create.rb 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. class Sessions::Backend::TicketCreate < Sessions::Backend::Base
  2. def load
  3. # get attributes to update
  4. ticket_create_attributes = Ticket::ScreenOptions.attributes_to_change(
  5. user: @user.id,
  6. )
  7. # no data exists
  8. return if !ticket_create_attributes
  9. # no change exists
  10. return if @last_change == ticket_create_attributes
  11. # remember last state
  12. @last_change = ticket_create_attributes
  13. ticket_create_attributes
  14. end
  15. def client_key
  16. "as::load::#{self.class}::#{@user.id}::#{@client_id}"
  17. end
  18. def push
  19. # check timeout
  20. timeout = Sessions::CacheIn.get(client_key)
  21. return if timeout
  22. # set new timeout
  23. Sessions::CacheIn.set(client_key, true, { expires_in: @ttl.seconds })
  24. data = load
  25. return if !data
  26. if !@client
  27. return {
  28. event: 'ticket_create_attributes',
  29. data: data,
  30. }
  31. end
  32. @client.log "push ticket_create for user #{@user.id}"
  33. @client.send(
  34. event: 'ticket_create_attributes',
  35. data: data,
  36. )
  37. end
  38. end