Class: Push::Message

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Daemon::DatabaseReconnectable
Defined in:
lib/push/message.rb

Instance Method Summary collapse

Methods included from Daemon::DatabaseReconnectable

#adaptor_errors, #check_database_is_connected, #database_connection_lost, #reconnect_database, #sleep_to_avoid_thrashing, #with_database_reconnect_and_retry

Instance Method Details

#deliver(connection) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/push/message.rb', line 14

def deliver(connection)
  begin
    connection.write(self.to_message)
    check_for_error(connection)

    # this makes no sense in the rails environment, but it does in the daemon
    with_database_reconnect_and_retry(connection.name) do
      self.delivered = true
      self.delivered_at = Time.now
      self.save!(:validate => false)
    end

    Push::Daemon.logger.info("[#{connection.name}] Message #{id} delivered to #{device}")
  rescue Push::DeliveryError, Push::DisconnectionError => error
    handle_delivery_error(error, connection)
    raise
  end
end