queue-bus 0.6.0 → 0.7.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 +4 -4
- data/.rubocop.yml +35 -0
- data/CHANGELOG.md +14 -0
- data/lib/queue-bus.rb +1 -2
- data/lib/queue_bus/config.rb +40 -72
- data/lib/queue_bus/version.rb +1 -1
- data/queue-bus.gemspec +1 -0
- data/spec/config_spec.rb +81 -40
- data/spec/spec_helper.rb +10 -5
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89735322de0ab91d94ca27b4f58598ef5049f829adfdc4788aa84eccd4d4597e
|
4
|
+
data.tar.gz: b6955c5ac09371018feddf9236f756de49c024ae1ac199b1498c00137761ab6d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4c49c5180981e584fa91e0ba8a185c82b82f9c82533b36a75e2dc57cab75ff327d3585ac109940f234c9414c64ebae33aaa1f54ccbf5ab4b0e16cd1965128bd
|
7
|
+
data.tar.gz: 7486eb2fbd2cb8ede93beb3af7b2046b224e74983986045577997f227d9df4e056aac8f8054bb42f09c1194354b4c0306c45a30c059c6cab099710365ee58a9e
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.4
|
3
|
+
ExtraDetails: true
|
4
|
+
|
5
|
+
# http://rubocop.readthedocs.io/en/latest/cops_style/#stylefrozenstringliteralcomment
|
6
|
+
Style/FrozenStringLiteralComment:
|
7
|
+
Enabled: true
|
8
|
+
|
9
|
+
# https://rubocop.readthedocs.io/en/latest/cops_style/#styledatetime
|
10
|
+
Style/DateTime:
|
11
|
+
Enabled: true
|
12
|
+
|
13
|
+
# http://rubocop.readthedocs.io/en/latest/cops_metrics/#metricslinelength
|
14
|
+
Metrics/LineLength:
|
15
|
+
Max: 100
|
16
|
+
|
17
|
+
Metrics/MethodLength:
|
18
|
+
Max: 15
|
19
|
+
|
20
|
+
Metrics/BlockLength:
|
21
|
+
Exclude:
|
22
|
+
- spec/**/*
|
23
|
+
|
24
|
+
# https://rubocop.readthedocs.io/en/latest/cops_layout/#layoutdotposition
|
25
|
+
Layout/DotPosition:
|
26
|
+
Enabled: true
|
27
|
+
EnforcedStyle: leading
|
28
|
+
|
29
|
+
# https://rubocop.readthedocs.io/en/latest/cops_style/#stylehashsyntax
|
30
|
+
Style/HashSyntax:
|
31
|
+
Enabled: true
|
32
|
+
|
33
|
+
# https://rubocop-rspec.readthedocs.io/en/latest/cops_rspec/#rspecfocus
|
34
|
+
RSpec/Focus:
|
35
|
+
Enabled: true
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [0.7.0]
|
10
|
+
|
11
|
+
### Added
|
12
|
+
- Adds `QueueBus.has_adapter?` to check whether the adapter is set.
|
13
|
+
|
14
|
+
### Changed
|
15
|
+
- Now uses `Process.hostname` to determine hostname versus relying on unix shell.
|
16
|
+
- Rubocop is now a dev dependency.
|
17
|
+
- Accessors to config are now done with actual attrs.
|
18
|
+
- Logging with the adapter will use the logger if present.
|
19
|
+
|
20
|
+
### Fixed
|
21
|
+
- Passing a class to `adapter=` would error on a `NameError`.
|
22
|
+
|
9
23
|
## [0.6.0]
|
10
24
|
|
11
25
|
### Added
|
data/lib/queue-bus.rb
CHANGED
@@ -38,7 +38,7 @@ module QueueBus
|
|
38
38
|
:before_publish=, :before_publish_callback,
|
39
39
|
:logger=, :logger, :log_application, :log_worker,
|
40
40
|
:hostname=, :hostname,
|
41
|
-
:adapter=, :adapter,
|
41
|
+
:adapter=, :adapter, :has_adapter?,
|
42
42
|
:incoming_queue=, :incoming_queue,
|
43
43
|
:redis, :worker_middleware_stack
|
44
44
|
|
@@ -60,5 +60,4 @@ module QueueBus
|
|
60
60
|
@_dispatchers ||= ::QueueBus::Dispatchers.new
|
61
61
|
end
|
62
62
|
end
|
63
|
-
|
64
63
|
end
|
data/lib/queue_bus/config.rb
CHANGED
@@ -1,102 +1,70 @@
|
|
1
|
-
|
2
|
-
class Config
|
3
|
-
def adapter=val
|
4
|
-
raise "Adapter already set to #{@adapter_instance.class.name}" if @adapter_instance
|
5
|
-
if val.is_a?(Class)
|
6
|
-
@adapter_instance = name_or_klass.new
|
7
|
-
elsif val.is_a?(::QueueBus::Adapters::Base)
|
8
|
-
@adapter_instance = val
|
9
|
-
else
|
10
|
-
class_name = ::QueueBus::Util.classify(val)
|
11
|
-
@adapter_instance = ::QueueBus::Util.constantize("::QueueBus::Adapters::#{class_name}").new
|
12
|
-
end
|
13
|
-
@adapter_instance
|
14
|
-
end
|
15
|
-
|
16
|
-
def adapter
|
17
|
-
return @adapter_instance if @adapter_instance
|
18
|
-
raise "no adapter has been set"
|
19
|
-
end
|
20
|
-
|
21
|
-
def redis(&block)
|
22
|
-
# TODO: could allow setting for non-redis adapters
|
23
|
-
adapter.redis(&block)
|
24
|
-
end
|
1
|
+
# frozen_string_literal: true
|
25
2
|
|
26
|
-
|
27
|
-
|
28
|
-
end
|
3
|
+
require 'socket'
|
4
|
+
require 'logger'
|
29
5
|
|
30
|
-
|
31
|
-
|
32
|
-
|
6
|
+
module QueueBus
|
7
|
+
# This class contains all the configuration for a running queue bus application.
|
8
|
+
class Config
|
9
|
+
attr_accessor :default_queue, :local_mode, :hostname, :incoming_queue, :logger
|
33
10
|
|
34
|
-
|
35
|
-
@default_queue = val
|
36
|
-
end
|
11
|
+
attr_reader :worker_middleware_stack
|
37
12
|
|
38
|
-
def
|
39
|
-
@
|
13
|
+
def initialize
|
14
|
+
@worker_middleware_stack = QueueBus::Middleware::Stack.new
|
15
|
+
@incoming_queue = 'bus_incoming'
|
16
|
+
@hostname = Socket.gethostname
|
40
17
|
end
|
41
18
|
|
42
|
-
def
|
43
|
-
@
|
44
|
-
end
|
19
|
+
def adapter=(val)
|
20
|
+
raise "Adapter already set to #{@adapter_instance.class.name}" if has_adapter?
|
45
21
|
|
46
|
-
|
47
|
-
|
22
|
+
@adapter_instance =
|
23
|
+
if val.is_a?(Class)
|
24
|
+
val.new
|
25
|
+
elsif val.is_a?(::QueueBus::Adapters::Base)
|
26
|
+
val
|
27
|
+
else
|
28
|
+
class_name = ::QueueBus::Util.classify(val)
|
29
|
+
::QueueBus::Util.constantize("::QueueBus::Adapters::#{class_name}").new
|
30
|
+
end
|
48
31
|
end
|
49
32
|
|
50
|
-
def
|
51
|
-
@
|
52
|
-
end
|
33
|
+
def adapter
|
34
|
+
return @adapter_instance if has_adapter?
|
53
35
|
|
54
|
-
|
55
|
-
@incoming_queue ||= "bus_incoming"
|
36
|
+
raise 'no adapter has been set'
|
56
37
|
end
|
57
38
|
|
58
|
-
|
59
|
-
|
39
|
+
# Checks whether an adapter is set and returns true if it is.
|
40
|
+
def has_adapter? # rubocop:disable Naming/PredicateName
|
41
|
+
!@adapter_instance.nil?
|
60
42
|
end
|
61
43
|
|
62
|
-
def
|
63
|
-
|
44
|
+
def redis(&block)
|
45
|
+
# TODO: could allow setting for non-redis adapters
|
46
|
+
adapter.redis(&block)
|
64
47
|
end
|
65
48
|
|
66
|
-
|
67
|
-
|
49
|
+
attr_reader :default_app_key
|
50
|
+
def default_app_key=(val)
|
51
|
+
@default_app_key = Application.normalize(val)
|
68
52
|
end
|
69
53
|
|
70
|
-
def before_publish=(
|
71
|
-
@before_publish_callback =
|
54
|
+
def before_publish=(callback)
|
55
|
+
@before_publish_callback = callback
|
72
56
|
end
|
73
57
|
|
74
58
|
def before_publish_callback(attributes)
|
75
|
-
|
76
|
-
@before_publish_callback.call(attributes)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def logger
|
81
|
-
@logger
|
82
|
-
end
|
83
|
-
|
84
|
-
def logger=val
|
85
|
-
@logger = val
|
59
|
+
@before_publish_callback&.call(attributes)
|
86
60
|
end
|
87
61
|
|
88
62
|
def log_application(message)
|
89
|
-
|
90
|
-
time = Time.now.strftime('%H:%M:%S %Y-%m-%d')
|
91
|
-
logger.info("** [#{time}] #$$: QueueBus #{message}")
|
92
|
-
end
|
63
|
+
logger&.info(message)
|
93
64
|
end
|
94
65
|
|
95
66
|
def log_worker(message)
|
96
|
-
|
97
|
-
time = Time.now.strftime('%H:%M:%S %Y-%m-%d')
|
98
|
-
puts "** [#{time}] #$$: #{message}"
|
99
|
-
end
|
67
|
+
logger&.debug(message)
|
100
68
|
end
|
101
69
|
end
|
102
70
|
end
|
data/lib/queue_bus/version.rb
CHANGED
data/queue-bus.gemspec
CHANGED
data/spec/config_spec.rb
CHANGED
@@ -1,83 +1,124 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
module QueueBus
|
4
|
-
module Adapters
|
5
|
-
class TestOne
|
1
|
+
# frozen_string_literal: true
|
6
2
|
|
7
|
-
|
8
|
-
end
|
9
|
-
end
|
3
|
+
require 'spec_helper'
|
10
4
|
|
11
|
-
describe
|
12
|
-
it
|
5
|
+
describe 'QueueBus config' do
|
6
|
+
it 'sets the default app key' do
|
13
7
|
expect(QueueBus.default_app_key).to eq(nil)
|
14
8
|
|
15
|
-
QueueBus.default_app_key =
|
16
|
-
expect(QueueBus.default_app_key).to eq(
|
9
|
+
QueueBus.default_app_key = 'my_app'
|
10
|
+
expect(QueueBus.default_app_key).to eq('my_app')
|
17
11
|
|
18
|
-
QueueBus.default_app_key =
|
19
|
-
expect(QueueBus.default_app_key).to eq(
|
12
|
+
QueueBus.default_app_key = 'something here'
|
13
|
+
expect(QueueBus.default_app_key).to eq('something_here')
|
20
14
|
end
|
21
15
|
|
22
|
-
it
|
16
|
+
it 'sets the default queue' do
|
23
17
|
expect(QueueBus.default_queue).to eq(nil)
|
24
18
|
|
25
|
-
QueueBus.default_queue =
|
26
|
-
expect(QueueBus.default_queue).to eq(
|
19
|
+
QueueBus.default_queue = 'my_queue'
|
20
|
+
expect(QueueBus.default_queue).to eq('my_queue')
|
27
21
|
end
|
28
22
|
|
29
|
-
it
|
23
|
+
it 'sets the local mode' do
|
30
24
|
expect(QueueBus.local_mode).to eq(nil)
|
31
25
|
QueueBus.local_mode = :standalone
|
32
26
|
expect(QueueBus.local_mode).to eq(:standalone)
|
33
27
|
end
|
34
28
|
|
35
|
-
it
|
29
|
+
it 'sets the hostname' do
|
36
30
|
expect(QueueBus.hostname).not_to eq(nil)
|
37
|
-
QueueBus.hostname =
|
38
|
-
expect(QueueBus.hostname).to eq(
|
31
|
+
QueueBus.hostname = 'whatever'
|
32
|
+
expect(QueueBus.hostname).to eq('whatever')
|
39
33
|
end
|
40
34
|
|
41
|
-
it
|
42
|
-
QueueBus.before_publish =
|
35
|
+
it 'sets before_publish callback' do
|
36
|
+
QueueBus.before_publish = ->(_attr) { 42 }
|
43
37
|
expect(QueueBus.before_publish_callback({})).to eq(42)
|
44
38
|
end
|
45
39
|
|
46
|
-
|
47
|
-
it "should use the default Redis connection" do
|
40
|
+
it 'uses the default Redis connection' do
|
48
41
|
expect(QueueBus.redis { |redis| redis }).not_to eq(nil)
|
49
42
|
end
|
50
43
|
|
51
|
-
it
|
44
|
+
it 'defaults to given adapter' do
|
52
45
|
expect(QueueBus.adapter.is_a?(adapter_under_test_class)).to eq(true)
|
53
46
|
|
54
47
|
# and should raise if already set
|
55
|
-
expect {
|
56
|
-
|
57
|
-
}.to raise_error(RuntimeError, "Adapter already set to QueueBus::Adapters::Data")
|
48
|
+
expect { QueueBus.adapter = :data }
|
49
|
+
.to raise_error(RuntimeError, 'Adapter already set to QueueBus::Adapters::Data')
|
58
50
|
end
|
59
51
|
|
60
|
-
context
|
52
|
+
context 'with a fresh load' do
|
61
53
|
before(:each) do
|
62
54
|
QueueBus.send(:reset)
|
63
55
|
end
|
64
56
|
|
65
|
-
|
66
|
-
|
67
|
-
|
57
|
+
context 'when set to adapter under test' do
|
58
|
+
before do
|
59
|
+
QueueBus.adapter = adapter_under_test_symbol
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'sets to that adapter' do
|
63
|
+
expect(QueueBus.adapter).to be_a adapter_under_test_class
|
64
|
+
end
|
65
|
+
end
|
68
66
|
|
69
|
-
|
70
|
-
|
67
|
+
context 'when already set' do
|
68
|
+
before do
|
71
69
|
QueueBus.adapter = :data
|
72
|
-
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'raises' do
|
73
|
+
expect { QueueBus.adapter = :data }
|
74
|
+
.to raise_error(RuntimeError, 'Adapter already set to QueueBus::Adapters::Data')
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'knows the adapter is set' do
|
78
|
+
expect(QueueBus).to have_adapter
|
79
|
+
end
|
73
80
|
end
|
74
81
|
|
75
|
-
|
82
|
+
context 'with a symbol' do
|
83
|
+
before do
|
84
|
+
QueueBus.adapter = :data
|
85
|
+
end
|
76
86
|
|
77
|
-
|
78
|
-
|
87
|
+
it 'looks up the known class' do
|
88
|
+
expect(QueueBus.adapter).to be_a QueueBus::Adapters::Data
|
89
|
+
end
|
79
90
|
end
|
80
|
-
end
|
81
91
|
|
92
|
+
context 'with a custom adapter' do
|
93
|
+
let(:klass) do
|
94
|
+
Class.new(QueueBus::Adapters::Base) do
|
95
|
+
def enabled!
|
96
|
+
# no op
|
97
|
+
end
|
98
|
+
|
99
|
+
def redis
|
100
|
+
# no op
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
before do
|
106
|
+
QueueBus.adapter = klass.new
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'sets it to something else' do
|
110
|
+
expect(QueueBus.adapter).to be_a klass
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
context 'with a class' do
|
115
|
+
before do
|
116
|
+
QueueBus.adapter = QueueBus::Adapters::Data
|
117
|
+
end
|
82
118
|
|
119
|
+
it 'creates a new one' do
|
120
|
+
expect(QueueBus.adapter).to be_a QueueBus::Adapters::Data
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
83
124
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'timecop'
|
2
4
|
require 'queue-bus'
|
3
5
|
require 'adapter/support'
|
@@ -33,9 +35,9 @@ module QueueBus
|
|
33
35
|
end
|
34
36
|
end
|
35
37
|
|
36
|
-
def test_sub(event_name, queue=
|
37
|
-
matcher = {
|
38
|
-
QueueBus::Subscription.new(queue, event_name,
|
38
|
+
def test_sub(event_name, queue = 'default')
|
39
|
+
matcher = { 'bus_event_type' => event_name }
|
40
|
+
QueueBus::Subscription.new(queue, event_name, '::QueueBus::Rider', matcher, nil)
|
39
41
|
end
|
40
42
|
|
41
43
|
def test_list(*args)
|
@@ -50,6 +52,7 @@ RSpec.configure do |config|
|
|
50
52
|
config.mock_with :rspec do |c|
|
51
53
|
c.syntax = :expect
|
52
54
|
end
|
55
|
+
|
53
56
|
config.expect_with :rspec do |c|
|
54
57
|
c.syntax = :expect
|
55
58
|
end
|
@@ -57,10 +60,12 @@ RSpec.configure do |config|
|
|
57
60
|
config.before(:each) do
|
58
61
|
reset_test_adapter
|
59
62
|
end
|
63
|
+
|
60
64
|
config.after(:each) do
|
61
65
|
begin
|
62
|
-
QueueBus.redis
|
63
|
-
rescue
|
66
|
+
QueueBus.redis(&:flushall)
|
67
|
+
rescue RuntimeError # rubocop:disable Lint/HandleExceptions
|
68
|
+
# We raise if redis isn't there.
|
64
69
|
end
|
65
70
|
QueueBus.send(:reset)
|
66
71
|
QueueBus::Runner1.reset
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: queue-bus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Leonard
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-07-
|
11
|
+
date: 2019-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
description: A simple event bus on top of common background queues. Publish and subscribe
|
84
98
|
to events as they occur using what you already have.
|
85
99
|
email:
|
@@ -91,6 +105,7 @@ files:
|
|
91
105
|
- ".gitignore"
|
92
106
|
- ".rbenv-version"
|
93
107
|
- ".rspec"
|
108
|
+
- ".rubocop.yml"
|
94
109
|
- ".rvmrc"
|
95
110
|
- CHANGELOG.md
|
96
111
|
- Gemfile
|