subserver 0.1.1 → 0.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4a000b5012eabb4cb6dd63890ebcfd6c7fb114fd
4
- data.tar.gz: ad5e305ef09bf8695711265cb5ef97b9b7e88ccb
3
+ metadata.gz: 024346e0b4fd27cc57e916d853d39b08de68d29f
4
+ data.tar.gz: d697e91f0fa56888c6a601fc58c66631fb64e61f
5
5
  SHA512:
6
- metadata.gz: 91bc0892c40cabfc4e45f18bc077c6c3d14febd0f16ee0ad971efd9122923881bb3a54c6067c3d480893802076977ca2a3bb3b5a567296bba685984249d26e2b
7
- data.tar.gz: 1df78a378a6990db9597e49a55b7f4719597eae63d714f292552e13e14de5cbd10b8741b43b671144713f9b8c674aaaad193fac4dee82e556d00a4b6eff1341d
6
+ metadata.gz: 0a3eaddf316cfe3910c59dde627db754e9f53941bf6614cf4e6fd2ce56f312dc1485eb1bcfef3af406fffd3ea6dcf6b10cc289be104a7ce138b9aa75e969392a
7
+ data.tar.gz: 64b24f88d670664662b2ee7eea621d3ef3aa19d4c8e8ca6f84b4489c7140afad07c031adb59587a20af6a0c7ea9128c7d0c0d348cd844beaeb4df0a80c728bef
@@ -68,6 +68,26 @@ module Subserver
68
68
  # Touch middleware so it isn't lazy loaded by multiple threads.
69
69
  Subserver.middleware
70
70
 
71
+ # Test Pubsub Connection
72
+ if ENV['PUBSUB_EMULATOR_HOST']
73
+ uri = URI.parse("http://#{ENV['PUBSUB_EMULATOR_HOST']}")
74
+ http = Net::HTTP.new(uri.host, uri.port)
75
+ begin
76
+ response = http.request_get(uri)
77
+ rescue Errno::ECONNREFUSED
78
+ logger.error "Errno::ECONNREFUSED - Could not connect to Pubsub Emulator at connection: #{ENV['PUBSUB_EMULATOR_HOST']}."
79
+ logger.info "If you are not intending to connect to the Pubsub Emulator remove the PUBSUB_EMULATOR_HOST environment variable."
80
+ die(1)
81
+ end
82
+ else
83
+ begin
84
+ client = Subserver::Pubsub.client
85
+ rescue StandardError => e
86
+ logger.error "Pubsub Connection Error: #{e.message}"
87
+ die(1)
88
+ end
89
+ end
90
+
71
91
  # Before this point, the process is initializing with just the main thread.
72
92
  # Starting here the process will now have multiple threads running.
73
93
  fire_event(:startup, reverse: false, reraise: true)
@@ -263,26 +283,6 @@ module Subserver
263
283
  die(1)
264
284
  end
265
285
 
266
- # Test Pubsub Connection
267
- if ENV['PUBSUB_EMULATOR_HOST']
268
- uri = URI.parse("http://#{ENV['PUBSUB_EMULATOR_HOST']}")
269
- http = Net::HTTP.new(uri.host, uri.port)
270
- begin
271
- response = http.request_get(uri)
272
- rescue Errno::ECONNREFUSED
273
- logger.error "Errno::ECONNREFUSED - Could not connect to Pubsub Emulator at connection: #{ENV['PUBSUB_EMULATOR_HOST']}."
274
- logger.info "If you are not intending to connect to the Pubsub Emulator remove the PUBSUB_EMULATOR_HOST environment variable."
275
- die(1)
276
- end
277
- else
278
- begin
279
- client = Subserver::Pubsub.client
280
- rescue StandardError => e
281
- logger.error "Pubsub Connection Error: #{e.message}"
282
- die(1)
283
- end
284
- end
285
-
286
286
  raise ArgumentError, "#{timeout}: #{options[:timeout]} is not a valid value" if options.has_key?(:timeout) && options[:timeout].to_i <= 0
287
287
  end
288
288
 
@@ -335,8 +335,8 @@ module Subserver
335
335
  opts[:logfile] = arg
336
336
  end
337
337
 
338
- o.on '-P', '--pidfile PATH', "path to pidfile" do |arg|
339
- opts[:pidfile] = arg
338
+ o.on '-P', '--port PORT', "port to expose health check on" do |arg|
339
+ opts[:health_port] = arg
340
340
  end
341
341
 
342
342
  o.on '-V', '--version', "Print version and exit" do |arg|
@@ -6,11 +6,12 @@ module Subserver
6
6
  attr_accessor :server
7
7
 
8
8
  def initialize
9
- @server = TCPServer.new 4481
9
+ @server = TCPServer.new Subserver.options[:health_port] || 4081
10
10
  end
11
11
 
12
- def start
12
+ def start
13
13
  begin
14
+ logger.debug "Health check avalible on port #{@server.addr[1]}"
14
15
  while session = @server.accept
15
16
  request = session.gets
16
17
 
@@ -29,5 +30,9 @@ module Subserver
29
30
  def stop
30
31
  @server.close
31
32
  end
33
+
34
+ def logger
35
+ Subserver.logger
36
+ end
32
37
  end
33
38
  end
@@ -29,7 +29,7 @@ module Subserver
29
29
 
30
30
  def initialize(mgr, subscriber)
31
31
  @mgr = mgr
32
- @down = false
32
+ @valid = true
33
33
  @done = false
34
34
  @thread = nil
35
35
  @reloader = Subserver.options[:reloader]
@@ -63,14 +63,18 @@ module Subserver
63
63
  @thread ||= safe_thread("listener", &method(:run))
64
64
  end
65
65
 
66
+ def valid?
67
+ @valid
68
+ end
69
+
66
70
  private unless $TESTING
67
71
 
68
72
  def retrive_subscrption
69
73
  subscription_name = @subscriber.get_subserver_options[:subscription]
70
- begin
71
- subscription = Pubsub.client.subscription subscription_name
72
- rescue Google::Cloud::Error => e
73
- raise ArgumentError, "Invalid Subscription name: #{subscription_name} Please ensure your Pubsub subscription exists."
74
+ subscription = Pubsub.client.subscription subscription_name rescue nil
75
+ if subscription.nil?
76
+ logger.error "ArgumentError: Invalid Subscription name: #{subscription_name} in subscriber #{@subscriber.name}. Please ensure your Pubsub subscription exists."
77
+ @valid = false
74
78
  end
75
79
  subscription
76
80
  end
@@ -25,6 +25,7 @@ module Subserver
25
25
 
26
26
  attr_reader :listeners
27
27
  attr_reader :options
28
+ attr_reader :subscribers
28
29
 
29
30
  def initialize(options={})
30
31
  logger.debug { options.inspect }
@@ -37,6 +38,8 @@ module Subserver
37
38
  @listeners << Listener.new(self, subscriber)
38
39
  end
39
40
 
41
+ @listeners.select!{ |l| l.valid? }
42
+
40
43
  @plock = Mutex.new
41
44
  end
42
45
 
@@ -92,14 +95,15 @@ module Subserver
92
95
  end
93
96
 
94
97
  def listener_died(listener, subscriber, reason)
95
- @plock.synchronize do
96
- @listeners.delete(listener)
97
- unless @done
98
- l = Listener.new(self, subscriber)
99
- @listeners << l
100
- l.start
101
- end
102
- end
98
+ logger.warn("Listener for #{subscriber.name} Died at #{Time.now}: #{reason}")
99
+ # @plock.synchronize do
100
+ # @listeners.delete(listener)
101
+ # unless @done
102
+ # l = Listener.new(self, subscriber)
103
+ # @listeners << l
104
+ # l.start
105
+ # end
106
+ # end
103
107
  end
104
108
 
105
109
  def stopped?
@@ -134,17 +138,14 @@ module Subserver
134
138
  # Expand Subscriber Directory from relative require
135
139
  path = File.expand_path("#{options[:subscriber_dir]}/*.rb")
136
140
 
137
- # Load existing set of classes
138
- existing_classes = ObjectSpace.each_object(Class).to_a
139
-
140
141
  # Require all subscriber files
141
142
  Dir[path].each { |f| require f }
142
143
 
143
- # Create set with only newly created classes from require loop
144
- new_classes = ObjectSpace.each_object(Class).to_a - existing_classes
144
+ # Create set of all classes including those in require loop
145
+ classes = ObjectSpace.each_object(Class).to_a
145
146
 
146
147
  # Only included named classes that have included the Subscriber module
147
- subscribers = new_classes.select do |klass|
148
+ subscribers = classes.select do |klass|
148
149
  klass.name && klass < ::Subserver::Subscriber && options[:queues].include?(klass.subserver_options[:queue])
149
150
  end
150
151
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Subserver
3
- VERSION = "0.1.1"
3
+ VERSION = "0.2.0"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: subserver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Hill
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-06 00:00:00.000000000 Z
11
+ date: 2018-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google-cloud-pubsub