diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f2a615..c00fb26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,2 +1,24 @@ -# 1.0.0 +# 0.4.0 +- Adds listener_startup lifecycle event + +# 0.3.0 +- Adds Mocks for testing in applications + +# 0.2.2 +- Fix issue where multi-subscriber options were getting overridden + +# 0.2.1 +- Use Rails 5 reloader +- Fix ActiveRecord connection issues using ConnectionHandler +- Use Google's Default Enviroment Variables for fallback + +# 0.2.0 +- Adds PubSub connection testing +- Fixes a case where subserver would infinitly kill and respawn listeners +- Cleans up logger code + +# 0.1.1 +- Fixes connection handling + +# 0.1.0 - Initial Public Release \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index 8904b63..f78480f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - subserver (0.2.2) + subserver (0.4.0) google-cloud-pubsub (~> 0.31, >= 0.31.0) GEM @@ -53,12 +53,12 @@ GEM arel (9.0.0) builder (3.2.3) coderay (1.1.2) - concurrent-ruby (1.0.5) + concurrent-ruby (1.1.4) crass (1.0.4) diff-lcs (1.3) docile (1.3.1) erubi (1.7.1) - faraday (0.15.3) + faraday (0.15.4) multipart-post (>= 1.2, < 3) globalid (0.4.1) activesupport (>= 4.2.0) @@ -66,15 +66,15 @@ GEM google-cloud-env (~> 1.0) google-cloud-env (1.0.5) faraday (~> 0.11) - google-cloud-pubsub (0.33.1) + google-cloud-pubsub (0.33.2) concurrent-ruby (~> 1.0) google-cloud-core (~> 1.2) google-gax (~> 1.3) grpc-google-iam-v1 (~> 0.6.9) - google-gax (1.4.0) + google-gax (1.5.0) google-protobuf (~> 3.2) googleapis-common-protos (>= 1.3.5, < 2.0) - googleauth (~> 0.6.2) + googleauth (>= 0.6.2, < 0.10.0) grpc (>= 1.7.2, < 2.0) rly (~> 0.2.3) google-protobuf (3.6.1) @@ -84,14 +84,14 @@ GEM grpc (~> 1.0) googleapis-common-protos-types (1.0.2) google-protobuf (~> 3.0) - googleauth (0.6.6) + googleauth (0.8.0) faraday (~> 0.12) jwt (>= 1.4, < 3.0) - memoist (~> 0.12) + memoist (~> 0.16) multi_json (~> 1.11) os (>= 0.9, < 2.0) signet (~> 0.7) - grpc (1.15.0) + grpc (1.17.1) google-protobuf (~> 3.1) googleapis-common-protos-types (~> 1.0.0) grpc-google-iam-v1 (0.6.9) diff --git a/lib/subserver.rb b/lib/subserver.rb index 744c61e..c2f1c9a 100644 --- a/lib/subserver.rb +++ b/lib/subserver.rb @@ -26,6 +26,7 @@ module Subserver death_handlers: [], lifecycle_events: { startup: [], + listener_startup: [], quiet: [], shutdown: [], heartbeat: [], diff --git a/lib/subserver/cli.rb b/lib/subserver/cli.rb index 3a8c235..ccda448 100644 --- a/lib/subserver/cli.rb +++ b/lib/subserver/cli.rb @@ -88,8 +88,8 @@ def run end end - # Before this point, the process is initializing with just the main thread. - # Starting here the process will now have multiple threads running. + # Until this point, the process is initializing with just the main thread. + # After this point the process will have multiple threads running. fire_event(:startup, reverse: false, reraise: true) logger.debug { "Middleware: #{Subserver.middleware.map(&:klass).join(', ')}" } diff --git a/lib/subserver/listener.rb b/lib/subserver/listener.rb index 87f91ee..b21a9a8 100644 --- a/lib/subserver/listener.rb +++ b/lib/subserver/listener.rb @@ -90,6 +90,8 @@ def connect_subscriber def run begin + # This begins the listener process in a forked thread + fire_event(:listener_startup, reverse: false, reraise: true) connect_subscriber @pubsub_listener.start rescue Subserver::Shutdown diff --git a/lib/subserver/version.rb b/lib/subserver/version.rb index d46ae4f..3feca0c 100644 --- a/lib/subserver/version.rb +++ b/lib/subserver/version.rb @@ -1,4 +1,4 @@ # frozen_string_literal: true module Subserver - VERSION = "0.3.0" + VERSION = "0.4.0" end \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4cd9428..53118f5 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -33,6 +33,8 @@ # rspec-expectations config goes here. You can use an alternate # assertion/expectation library such as wrong or the stdlib/minitest # assertions if you prefer. + config.filter_run_when_matching :focus + config.expect_with :rspec do |expectations| # This option will default to `true` in RSpec 4. It makes the `description` # and `failure_message` of custom matchers include text for helper methods @@ -78,8 +80,8 @@ topic = client.topic "test" if topic.nil? topic = client.create_topic "test" - subscription = topic.subscribe "test-subscriber-1" - subscription = topic.subscribe "test-subscriber-2" + subscription = topic.subscribe "test-subscription-1" + subscription = topic.subscribe "test-subscription-2" end end @@ -91,7 +93,7 @@ # is tagged with `:focus`, all examples get run. RSpec also provides # aliases for `it`, `describe`, and `context` that include `:focus` # metadata: `fit`, `fdescribe` and `fcontext`, respectively. - config.filter_run_when_matching :focus + # Allows RSpec to persist some state between runs in order to support # the `--only-failures` and `--next-failure` CLI options. We recommend diff --git a/spec/subserver_spec.rb b/spec/subserver_spec.rb index f2a9a7e..96c203f 100644 --- a/spec/subserver_spec.rb +++ b/spec/subserver_spec.rb @@ -1,4 +1,6 @@ require 'spec_helper' +require_relative '../lib/subserver/listener' +require_relative '../lib/subserver/manager' RSpec.describe Subserver do @@ -16,5 +18,47 @@ it 'loads when file exists' it 'errors when file doesn\'t exit' end + + describe 'live cycle events' do + + let(:testclass) { + Class.new do + def ping + true + end + end + } + + let(:test_subscriber) { + Class.new do + include Subserver::Subscriber + subserver_options subscription: "test-subscription-1" + + def perform + true + end + end + } + + before do + @tester = testclass.new + Subserver.configure do |config| + config.on(:listener_startup) do + @tester.ping + end + end + + @manager = instance_double("Subserver::Manager") + allow(@manager).to receive(:options) { Subserver.options } + end + + describe 'listener_startup event' do + it 'runs when listener started' do + expect(@tester).to receive(:ping) + listener = Subserver::Listener.new(@manager, test_subscriber) + listener.fire_event(:listener_startup, reverse: false, reraise: true) + end + end + end end \ No newline at end of file