Skip to content

Commit

Permalink
Merge pull request #8 from lifechurch/0.4.0
Browse files Browse the repository at this point in the history
0.4.0
  • Loading branch information
paradigm314 authored Jan 10, 2019
2 parents fd57ab7 + fec6651 commit ddbee60
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 16 deletions.
24 changes: 23 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
18 changes: 9 additions & 9 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
subserver (0.2.2)
subserver (0.4.0)
google-cloud-pubsub (~> 0.31, >= 0.31.0)

GEM
Expand Down Expand Up @@ -53,28 +53,28 @@ 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)
google-cloud-core (1.2.7)
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)
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions lib/subserver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module Subserver
death_handlers: [],
lifecycle_events: {
startup: [],
listener_startup: [],
quiet: [],
shutdown: [],
heartbeat: [],
Expand Down
4 changes: 2 additions & 2 deletions lib/subserver/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(', ')}" }
Expand Down
2 changes: 2 additions & 0 deletions lib/subserver/listener.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/subserver/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: true
module Subserver
VERSION = "0.3.0"
VERSION = "0.4.0"
end
8 changes: 5 additions & 3 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down
44 changes: 44 additions & 0 deletions spec/subserver_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
require 'spec_helper'
require_relative '../lib/subserver/listener'
require_relative '../lib/subserver/manager'

RSpec.describe Subserver do

Expand All @@ -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

0 comments on commit ddbee60

Please sign in to comment.