hanami-events-cloud_pubsub 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f2a054059dd8bf27cccccc92f417df3761a54fd9
4
- data.tar.gz: 49e74a3600f6e1ad33d95afb64f4553c1a6f8040
3
+ metadata.gz: 88120cf9f817872c49197ae567f89522ea1f4b2a
4
+ data.tar.gz: 758ef846e83c6fc98167d57935035746126b9cec
5
5
  SHA512:
6
- metadata.gz: ca596841b1e75b421f9ce5beca750538dbf1223a43b082caad96b6c8c63c0255bee763515f0aec0f08998fdfd459565454a309aa2a5d50cb269d4eb3b2972d14
7
- data.tar.gz: 6f7bee64cb6eb48929b8a2efbec2b8d9f73e2cb887536001577b705cc8d7b596e50654e0d6907fc58140ca4d6a2de4a81cf3fce875da3496b6059187c2401d39
6
+ metadata.gz: 9e303a3232233768644db08dfc82b71dff839240c983c0f097d778b514a8613331116baa6906ddc9cf8ccb0146b8278f698e63c055b8b900ea1fb05b52cd5190
7
+ data.tar.gz: 7daa16544379cbf1a72d05bd8eb558285899c102fbf0fe99302a80629678daaa3d56acda34030830aac9339c6663c9a37e3aa4f8085c9c05083c5a6733a00d0e
data/Gemfile.lock CHANGED
@@ -9,12 +9,11 @@ GIT
9
9
  PATH
10
10
  remote: .
11
11
  specs:
12
- hanami-events-cloud_pubsub (0.2.5)
12
+ hanami-events-cloud_pubsub (0.2.6)
13
13
  dry-configurable (~> 0.7.0)
14
14
  google-cloud-pubsub (~> 0.30.2)
15
15
  hanami-cli (~> 0.2.0)
16
16
  hanami-events (~> 0)
17
- rack (~> 2.0.5)
18
17
 
19
18
  GEM
20
19
  remote: https://rubygems.org/
@@ -95,7 +94,6 @@ GEM
95
94
  coderay (~> 1.1.0)
96
95
  method_source (~> 0.9.0)
97
96
  public_suffix (3.0.2)
98
- rack (2.0.5)
99
97
  rainbow (3.0.0)
100
98
  rake (12.3.1)
101
99
  rly (0.2.3)
@@ -26,7 +26,6 @@ Gem::Specification.new do |spec|
26
26
  spec.add_dependency 'google-cloud-pubsub', '~> 0.30.2'
27
27
  spec.add_dependency 'hanami-cli', '~> 0.2.0'
28
28
  spec.add_dependency 'hanami-events', '~> 0'
29
- spec.add_dependency 'rack', '~> 2.0.5'
30
29
 
31
30
  spec.add_development_dependency 'bundler', '~> 1.16'
32
31
  spec.add_development_dependency 'rake', '~> 12.3'
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rack'
3
+ require 'webrick'
4
4
 
5
5
  module Hanami
6
6
  module Events
@@ -13,44 +13,44 @@ module Hanami
13
13
  end
14
14
 
15
15
  def start
16
- @logger.info 'Starting healthcheck server on port 0.0.0.0:8080'
16
+ logger.info 'Starting healthcheck server on port 0.0.0.0:8080'
17
17
  server.start
18
18
  end
19
19
 
20
- def run_in_background(on_shutdown:)
21
- log_error = proc { |err| logger.error(err.message) }
20
+ def shutdown
21
+ logger.info 'Shutting down healthcheck server'
22
+ server.shutdown
23
+ end
22
24
 
23
- Concurrent::Promise.execute(on_reject: log_error) do
24
- server.start
25
- on_shutdown.call(server)
25
+ def run_in_background(on_shutdown: nil)
26
+ prom = Concurrent::Promise.execute do
27
+ start
28
+ on_shutdown&.call(server)
26
29
  end
30
+
31
+ prom.catch { |err| logger.error(err) }
27
32
  end
28
33
 
29
34
  private
30
35
 
31
- def server
32
- @server ||= Rack::Server.new(
33
- Port: 8080,
34
- Host: '0.0.0.0',
35
- quiet: true,
36
- app: app
37
- )
38
- end
39
-
40
- def app
41
- health_endpoint = method(:health_endpoint)
36
+ attr_reader :logger, :runner
42
37
 
43
- Rack::Builder.app do
44
- run health_endpoint
45
- end
38
+ def server
39
+ @server ||=
40
+ WEBrick::HTTPServer.new(
41
+ Port: 8080,
42
+ BindAddress: '0.0.0.0',
43
+ Logger: WEBrick::Log.new('/dev/null'),
44
+ AccessLog: []
45
+ ).tap do |srv|
46
+ srv.mount_proc '/', method(:health_endpoint)
47
+ end
46
48
  end
47
49
 
48
- def health_endpoint(_env)
49
- status = @runner.healthy? ? 200 : 503
50
- headers = { 'Content-Type' => 'text/html' }
51
- body = [status.to_s]
52
-
53
- [status, headers, body]
50
+ def health_endpoint(_req, res)
51
+ res['Content-Type'] = 'text/plain'
52
+ res.status = runner.healthy? ? 200 : 503
53
+ res.body = res.status.to_s
54
54
  end
55
55
  end
56
56
  end
@@ -25,11 +25,8 @@ module Hanami
25
25
  # Will be called on TSTP
26
26
  #
27
27
  # Stop processing new events (unsubscribe from topics, etc)
28
- #
29
- # For example, if you needed to restart a Redis server you could first
30
- # call pause to allow for a safe restart of the runner.
31
- def pause
32
- logger.info 'Pausing CloudPubsub runner'
28
+ def stop
29
+ logger.info 'Stopping CloudPubsub listeners'
33
30
  adapter.listeners.each(&:stop)
34
31
  self
35
32
  end
@@ -40,7 +37,7 @@ module Hanami
40
37
  # waiting for messages to finish processing, etc. If this method succesfully
41
38
  # runs, there should be no potential for undefined behavior.
42
39
  def gracefully_shutdown
43
- pause
40
+ stop
44
41
  logger.info "Gracefully shutting down CloudPubsub runner: #{self}"
45
42
  sleep_for_a_bit
46
43
  adapter.flush_messages
@@ -3,7 +3,7 @@
3
3
  module Hanami
4
4
  module Events
5
5
  module CloudPubsub
6
- VERSION = '0.2.5'
6
+ VERSION = '0.2.6'
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hanami-events-cloud_pubsub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ian Ker-Seymer
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-06-12 00:00:00.000000000 Z
11
+ date: 2018-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-configurable
@@ -66,20 +66,6 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: rack
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: 2.0.5
76
- type: :runtime
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: 2.0.5
83
69
  - !ruby/object:Gem::Dependency
84
70
  name: bundler
85
71
  requirement: !ruby/object:Gem::Requirement