suj-pusher 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/bin/pusher CHANGED
@@ -20,14 +20,20 @@ class PusherDaemon < DaemonSpawn::Base
20
20
  end
21
21
  end
22
22
 
23
- redis = "redis://localhost:6379/pusher"
23
+ redis_host = "localhost"
24
+ redis_port = 6379
25
+ redis_db = 0
26
+ redis_namespace = "pusher"
24
27
  logdir = File.join(WORKDIR, "logs")
25
28
  piddir = File.join(WORKDIR, "pids")
26
29
  cerdir = File.join(WORKDIR, "certs")
27
30
 
28
31
  ARGV.options do |opts|
29
32
  opts.banner = BANNER
30
- opts.on('-r REDIS', '--redis REDIS', String, 'Redis server to connect') { |r|redis = r }
33
+ opts.on('-h REDIS HOST', '--host REDIS HOST', String, 'Redis server to connect') { |host| redis_host = host }
34
+ opts.on('-P REDIS PORT', '--port REDIS PORT', String, 'Redis server port') { |port| redis_port = port }
35
+ opts.on('-b REDIS DB', '--db REDIS DB', String, 'Redis database number') { |db| redis_db = db }
36
+ opts.on('-n REDIS NAMESPACE', '--namespace REDIS NAMESPACE', String, 'Redis server namespace') { |name| redis_namespace = name }
31
37
  opts.on('-l LOGS', '--logdir LOGS', String, 'Logs destination directory') { |l| logdir = l }
32
38
  opts.on('-p PIDS', '--piddir PIDS', String, 'Pids destination diercoty') { |pid| piddir = pid }
33
39
  opts.on('-c CERTS', '--cerdir CERTS', String, 'Directory to store certificates') { |cert| cerdir = cert }
@@ -42,7 +48,10 @@ FileUtils.mkdir_p(piddir)
42
48
 
43
49
  config = Suj::Pusher::Configuration.new
44
50
  config.certs_path = cerdir
45
- config.redis = redis
51
+ config.redis_host = redis_host
52
+ config.redis_port = redis_port
53
+ config.redis_db = redis_db
54
+ config.redis_namespace = redis_namespace
46
55
  Suj::Pusher.config.update(config)
47
56
 
48
57
  PusherDaemon.spawn!(
@@ -13,7 +13,10 @@ module Suj
13
13
  :certs_path,
14
14
  :workdir,
15
15
  :logger,
16
- :redis
16
+ :redis_host,
17
+ :redis_port,
18
+ :redis_db,
19
+ :redis_namespace
17
20
  ]
18
21
 
19
22
  class Configuration < Struct.new(*CONFIG_ATTRS)
@@ -31,7 +34,10 @@ module Suj
31
34
  end
32
35
 
33
36
  def set_defaults
34
- self.redis = "redis://localhost:6379"
37
+ self.redis_host = "localhost"
38
+ self.redis_port = 6379
39
+ self.redis_db = 0
40
+ self.redis_namespace = "pusher"
35
41
  self.logger = ::Logger.new(STDOUT)
36
42
  end
37
43
 
@@ -15,7 +15,7 @@ module Suj
15
15
 
16
16
  def start
17
17
  info "Starting pusher daemon"
18
- info " subsribe to push messages from #{Suj::Pusher.config.redis}"
18
+ info " subsribe to push messages from #{redis_url} namespace #{redis_namespace}"
19
19
  EM.run do
20
20
  wait_msg do |msg|
21
21
  begin
@@ -47,14 +47,14 @@ module Suj
47
47
  private
48
48
 
49
49
  def wait_msg
50
- redis.on(:connected) { info "REDIS - Connected to Redis server" }
50
+ redis.on(:connected) { info "REDIS - Connected to Redis server #{redis_url}" }
51
51
  redis.on(:closed) { info "REDIS - Closed connection to Redis server" }
52
52
  redis.on(:failed) { info "REDIS - redis connection FAILED" }
53
53
  redis.on(:reconnected) { info "REDIS - Reconnected to Redis server" }
54
54
  redis.on(:disconnected) { info "REDIS - Disconnected from Redis server" }
55
55
  redis.on(:reconnect_failed) { info "REDIS - Reconnection attempt to Redis server FAILED" }
56
56
  # EM.add_periodic_timer(30) { redis.publish Suj::Pusher::QUEUE, "ECHO" }
57
- redis.pubsub.subscribe(Suj::Pusher::QUEUE) do |msg|
57
+ redis.pubsub.subscribe("#{redis_namespace}:#{Suj::Pusher::QUEUE}") do |msg|
58
58
  if msg == "ECHO"
59
59
  info "REDIS - ECHO Received"
60
60
  elsif msg == "PUSH_MSG"
@@ -132,13 +132,21 @@ module Suj
132
132
  conn.deliver(msg)
133
133
  end
134
134
 
135
+ def redis_url
136
+ @redis_url ||= "redis://#{Suj::Pusher.config.redis_host}:#{Suj::Pusher.config.redis_port}/#{Suj::Pusher.config.redis_db}"
137
+ end
138
+
139
+ def redis_namespace
140
+ Suj::Pusher.config.redis_namespace
141
+ end
142
+
135
143
  def redis
136
- @redis ||= EM::Hiredis.connect(Suj::Pusher.config.redis)
144
+ @redis ||= EM::Hiredis.connect(redis_url)
137
145
  end
138
146
 
139
147
  def get_message
140
- @redis_connection ||= EM::Hiredis.connect(Suj::Pusher.config.redis)
141
- @redis_connection.rpop MSG_QUEUE
148
+ @redis_connection ||= EM::Hiredis.connect(redis_url)
149
+ @redis_connection.rpop "#{redis_namespace}:#{MSG_QUEUE}"
142
150
  end
143
151
 
144
152
  def pool
@@ -1,5 +1,5 @@
1
1
  module Suj
2
2
  module Pusher
3
- VERSION = '0.1.3'
3
+ VERSION = '0.1.4'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: suj-pusher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2013-10-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: em-http-request
16
- requirement: &24896380 !ruby/object:Gem::Requirement
16
+ requirement: &18305600 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *24896380
24
+ version_requirements: *18305600
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: em-hiredis
27
- requirement: &24895960 !ruby/object:Gem::Requirement
27
+ requirement: &18303540 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *24895960
35
+ version_requirements: *18303540
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: multi_json
38
- requirement: &24895540 !ruby/object:Gem::Requirement
38
+ requirement: &24562640 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *24895540
46
+ version_requirements: *24562640
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: daemon-spawn
49
- requirement: &24895120 !ruby/object:Gem::Requirement
49
+ requirement: &24562220 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *24895120
57
+ version_requirements: *24562220
58
58
  description: Stand alone push notification server for APN and GCM.
59
59
  email:
60
60
  - rd@skillupjapan.co.jp