push-core 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +29 -0
- data/lib/push/configuration.rb +1 -1
- data/lib/push/daemon/app.rb +8 -5
- data/lib/push/daemon/database_reconnectable.rb +13 -4
- data/lib/push/daemon/logger.rb +8 -3
- data/lib/push/feedback.rb +1 -1
- data/lib/push/message.rb +1 -1
- data/lib/push/version.rb +1 -1
- metadata +6 -6
data/README.md
CHANGED
@@ -142,6 +142,35 @@ Push runs on Heroku with the following line in the `Procfile`.
|
|
142
142
|
|
143
143
|
push: bundle exec push $RACK_ENV -f
|
144
144
|
|
145
|
+
## Capistrano
|
146
|
+
|
147
|
+
Capistrano recipe using the pid file.
|
148
|
+
```ruby
|
149
|
+
after "deploy:stop", "push:stop"
|
150
|
+
after "deploy:start", "push:start"
|
151
|
+
before "deploy:restart", "push:restart"
|
152
|
+
|
153
|
+
set(:pushd_pid_file) { "#{current_path}/tmp/pids/push_daemon.pid" }
|
154
|
+
|
155
|
+
namespace :push do
|
156
|
+
desc 'Start the push daemon'
|
157
|
+
task :start, :roles => :worker do
|
158
|
+
run "cd #{current_path} ; nohup bundle exec push #{rails_env} -p #{pushd_pid_file} >> #{current_path}/log/push.log 2>&1 &", :pty => false
|
159
|
+
end
|
160
|
+
|
161
|
+
desc 'Stop the push daemon'
|
162
|
+
task :stop, :roles => :worker do
|
163
|
+
run "if [ -d #{current_path} ] && [ -f #{pushd_pid_file} ] && kill -0 `cat #{pushd_pid_file}`> /dev/null 2>&1; then kill -SIGINT `cat #{pushd_pid_file}` ; else echo 'push daemon is not running'; fi"
|
164
|
+
end
|
165
|
+
|
166
|
+
desc "Restart the push daemon"
|
167
|
+
task :restart, :roles => :worker do
|
168
|
+
stop
|
169
|
+
start
|
170
|
+
end
|
171
|
+
end
|
172
|
+
```
|
173
|
+
|
145
174
|
## Prerequisites
|
146
175
|
|
147
176
|
* Rails 3.2.x
|
data/lib/push/configuration.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Push
|
2
2
|
class Configuration < ActiveRecord::Base
|
3
3
|
self.table_name = 'push_configurations'
|
4
|
-
scope :enabled, where(:enabled => true)
|
4
|
+
scope :enabled, -> { where(:enabled => true) }
|
5
5
|
validates :app, :presence => true
|
6
6
|
validates :connections, :presence => true
|
7
7
|
validates :connections, :numericality => { :greater_than => 0, :only_integer => true }
|
data/lib/push/daemon/app.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module Push
|
2
2
|
module Daemon
|
3
3
|
class App
|
4
|
+
extend DatabaseReconnectable
|
4
5
|
class << self
|
5
6
|
attr_reader :apps
|
6
7
|
end
|
@@ -8,12 +9,14 @@ module Push
|
|
8
9
|
@apps = {}
|
9
10
|
|
10
11
|
def self.load
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
@apps[config.app]
|
12
|
+
with_database_reconnect_and_retry('App.load') do
|
13
|
+
configurations = Push::Configuration.enabled
|
14
|
+
configurations.each do |config|
|
15
|
+
if @apps[config.app] == nil
|
16
|
+
@apps[config.app] = App.new(config.app)
|
17
|
+
end
|
18
|
+
@apps[config.app].configs << config
|
15
19
|
end
|
16
|
-
@apps[config.app].configs << config
|
17
20
|
end
|
18
21
|
end
|
19
22
|
|
@@ -3,8 +3,12 @@ module Push
|
|
3
3
|
module DatabaseReconnectable
|
4
4
|
def adaptor_errors
|
5
5
|
errors = [ActiveRecord::StatementInvalid, ActiveRecord::ConnectionNotEstablished]
|
6
|
-
|
7
|
-
|
6
|
+
if defined?(::PG::Error)
|
7
|
+
errors << ::PG::Error
|
8
|
+
elsif defined?(::PGError)
|
9
|
+
errors << ::PGError
|
10
|
+
end
|
11
|
+
errors << ::Mysql2::Error if defined?(::Mysql2)
|
8
12
|
errors
|
9
13
|
end
|
10
14
|
|
@@ -36,8 +40,13 @@ module Push
|
|
36
40
|
end
|
37
41
|
|
38
42
|
def reconnect_database
|
39
|
-
|
40
|
-
|
43
|
+
begin
|
44
|
+
ActiveRecord::Base.clear_all_connections!
|
45
|
+
rescue
|
46
|
+
Push::Daemon.logger.error("ActiveRecord::Base.clear_all_connections! failed")
|
47
|
+
ensure
|
48
|
+
ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[ENV['RAILS_ENV']])
|
49
|
+
end
|
41
50
|
end
|
42
51
|
|
43
52
|
def check_database_is_connected
|
data/lib/push/daemon/logger.rb
CHANGED
@@ -37,7 +37,7 @@ module Push
|
|
37
37
|
|
38
38
|
if @options[:foreground]
|
39
39
|
puts formatted_msg
|
40
|
-
|
40
|
+
elsif @logger
|
41
41
|
@logger.send(where, formatted_msg)
|
42
42
|
end
|
43
43
|
end
|
@@ -45,8 +45,13 @@ module Push
|
|
45
45
|
def open_log
|
46
46
|
log_file = File.open(File.join(Rails.root, 'log', 'push.log'), 'a')
|
47
47
|
log_file.sync = true
|
48
|
-
|
49
|
-
|
48
|
+
|
49
|
+
if defined?(ActiveSupport::BufferedLogger)
|
50
|
+
@logger = ActiveSupport::BufferedLogger.new(log_file, Rails.logger.level)
|
51
|
+
@logger.auto_flushing = Rails.logger.respond_to?(:auto_flushing) ? Rails.logger.auto_flushing : true
|
52
|
+
elsif defined?(ActiveSupport::Logger)
|
53
|
+
@logger = ActiveSupport::Logger.new(log_file, Rails.logger.level)
|
54
|
+
end
|
50
55
|
end
|
51
56
|
|
52
57
|
def error_notification(e, options)
|
data/lib/push/feedback.rb
CHANGED
@@ -3,7 +3,7 @@ module Push
|
|
3
3
|
include Push::Daemon::DatabaseReconnectable
|
4
4
|
self.table_name = 'push_feedback'
|
5
5
|
|
6
|
-
scope :ready_for_followup, where(:processed => false)
|
6
|
+
scope :ready_for_followup, -> { where(:processed => false) }
|
7
7
|
validates :app, :presence => true
|
8
8
|
validates :device, :presence => true
|
9
9
|
validates :follow_up, :presence => true
|
data/lib/push/message.rb
CHANGED
@@ -9,7 +9,7 @@ module Push
|
|
9
9
|
validates :app, :presence => true
|
10
10
|
validates :device, :presence => true
|
11
11
|
|
12
|
-
scope :ready_for_delivery,
|
12
|
+
scope :ready_for_delivery, -> { where('delivered = ? AND failed = ? AND (deliver_after IS NULL OR deliver_after < ?)', false, false, Time.now) }
|
13
13
|
|
14
14
|
def deliver(connection)
|
15
15
|
begin
|
data/lib/push/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: push-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,24 +9,24 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-07-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
|
-
- -
|
19
|
+
- - ! '>'
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 3.2
|
21
|
+
version: '3.2'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - ! '>'
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 3.2
|
29
|
+
version: '3.2'
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: multi_json
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|