rapns 3.2.0-java → 3.3.0-java
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +5 -0
- data/README.md +9 -18
- data/lib/generators/templates/rapns.rb +5 -0
- data/lib/rapns.rb +4 -0
- data/lib/rapns/apns_feedback.rb +1 -0
- data/lib/rapns/configuration.rb +4 -3
- data/lib/rapns/daemon.rb +20 -4
- data/lib/rapns/daemon/apns/feedback_receiver.rb +9 -11
- data/lib/rapns/daemon/delivery.rb +3 -20
- data/lib/rapns/daemon/delivery_queue.rb +2 -2
- data/lib/rapns/daemon/feeder.rb +5 -10
- data/lib/rapns/daemon/gcm/delivery.rb +19 -9
- data/lib/rapns/daemon/store/active_record.rb +74 -0
- data/lib/rapns/daemon/store/active_record/reconnectable.rb +61 -0
- data/lib/rapns/gcm/notification.rb +5 -4
- data/lib/rapns/gcm/registration_ids_count_validator.rb +1 -1
- data/lib/rapns/logger.rb +6 -2
- data/lib/rapns/push.rb +1 -0
- data/lib/rapns/reflection.rb +1 -1
- data/lib/rapns/version.rb +1 -1
- data/spec/unit/apns/notification_spec.rb +2 -0
- data/spec/unit/apns_feedback_spec.rb +5 -0
- data/spec/unit/configuration_spec.rb +1 -1
- data/spec/unit/daemon/apns/delivery_spec.rb +7 -64
- data/spec/unit/daemon/apns/feedback_receiver_spec.rb +2 -2
- data/spec/unit/daemon/feeder_spec.rb +6 -58
- data/spec/unit/daemon/gcm/delivery_spec.rb +49 -57
- data/spec/unit/daemon/{database_reconnectable_spec.rb → store/active_record/reconnectable_spec.rb} +4 -3
- data/spec/unit/daemon/store/active_record_spec.rb +181 -0
- data/spec/unit/daemon_spec.rb +27 -7
- data/spec/unit/gcm/notification_spec.rb +2 -9
- data/spec/unit/push_spec.rb +5 -0
- data/spec/unit/reflection_spec.rb +0 -4
- data/spec/unit_spec_helper.rb +4 -1
- metadata +28 -25
- data/lib/rapns/daemon/database_reconnectable.rb +0 -57
@@ -1,57 +0,0 @@
|
|
1
|
-
class PGError < StandardError; end if !defined?(PGError)
|
2
|
-
class Mysql; class Error < StandardError; end; end if !defined?(Mysql)
|
3
|
-
module Mysql2; class Error < StandardError; end; end if !defined?(Mysql2)
|
4
|
-
module ActiveRecord; end
|
5
|
-
class ActiveRecord::JDBCError < StandardError; end if !defined?(ActiveRecord::JDBCError)
|
6
|
-
|
7
|
-
module Rapns
|
8
|
-
module Daemon
|
9
|
-
module DatabaseReconnectable
|
10
|
-
ADAPTER_ERRORS = [ActiveRecord::StatementInvalid, PGError, Mysql::Error,
|
11
|
-
Mysql2::Error, ActiveRecord::JDBCError]
|
12
|
-
|
13
|
-
def with_database_reconnect_and_retry
|
14
|
-
begin
|
15
|
-
ActiveRecord::Base.connection_pool.with_connection do
|
16
|
-
yield
|
17
|
-
end
|
18
|
-
rescue *ADAPTER_ERRORS => e
|
19
|
-
Rapns.logger.error(e)
|
20
|
-
database_connection_lost
|
21
|
-
retry
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def database_connection_lost
|
26
|
-
Rapns.logger.warn("Lost connection to database, reconnecting...")
|
27
|
-
attempts = 0
|
28
|
-
loop do
|
29
|
-
begin
|
30
|
-
Rapns.logger.warn("Attempt #{attempts += 1}")
|
31
|
-
reconnect_database
|
32
|
-
check_database_is_connected
|
33
|
-
break
|
34
|
-
rescue *ADAPTER_ERRORS => e
|
35
|
-
Rapns.logger.error(e, :airbrake_notify => false)
|
36
|
-
sleep_to_avoid_thrashing
|
37
|
-
end
|
38
|
-
end
|
39
|
-
Rapns.logger.warn("Database reconnected")
|
40
|
-
end
|
41
|
-
|
42
|
-
def reconnect_database
|
43
|
-
ActiveRecord::Base.clear_all_connections!
|
44
|
-
ActiveRecord::Base.establish_connection
|
45
|
-
end
|
46
|
-
|
47
|
-
def check_database_is_connected
|
48
|
-
# Simply asking the adapter for the connection state is not sufficient.
|
49
|
-
Rapns::Notification.count
|
50
|
-
end
|
51
|
-
|
52
|
-
def sleep_to_avoid_thrashing
|
53
|
-
sleep 2
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|