active_publisher 0.4.0 → 1.0.0.pre0

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: 43f2f004720a93d84b71d684c9525eb8a337a2f4
4
- data.tar.gz: be5c9ea51e3f4bed11905d5ac02352ef1f263330
3
+ metadata.gz: c47b026ffd14970af0fdd93efb07c7cc5fa6b649
4
+ data.tar.gz: 643480a2b1495381a8c6ccfedbdf0d249288def0
5
5
  SHA512:
6
- metadata.gz: 2158504c8060d878fb152a5682d6b96831badd30ad0e40a71e67e86baa1bb696c930d783c9ba9ddb7fd005fbe63a4404310918ac4a31271f335dcbf8c3aabaa2
7
- data.tar.gz: 56f42766ac91b76d93857258e854726f327f33152a71908f1870d3fc4eb7e8895b0fef44de6f3f764eea59ac99671a8dfa506f4e100fec02d613841ad31b3967
6
+ metadata.gz: 959a8d3a200142c30396ee065fdbb75d8d340eb8f474479c7e98c82795af5dd063eebe90a34156e7bc3e5795512ee20487d8e748ee915f19ae7eaa2a98fdf150
7
+ data.tar.gz: 6509995dad25e4f492b257f626cab11a3ea8b9b5b759526c24d32c10cafcf72b79c322bcd91910e6853b9955af1477345eac8a69f0669d7dfe532b5ebae47f6b
@@ -18,11 +18,11 @@ module ActivePublisher
18
18
 
19
19
  attr_reader :async_queue
20
20
 
21
- def initialize(drop_messages_when_queue_full = false, max_queue_size = 1_000_000, supervisor_interval = 0.2)
21
+ def initialize(back_pressure_strategy = :raise, max_queue_size = 100_000, supervisor_interval = 0.2)
22
22
  logger.info "Starting in-memory publisher adapter"
23
23
 
24
24
  @async_queue = ::ActivePublisher::Async::InMemoryAdapter::AsyncQueue.new(
25
- drop_messages_when_queue_full,
25
+ back_pressure_strategy,
26
26
  max_queue_size,
27
27
  supervisor_interval
28
28
  )
@@ -2,30 +2,44 @@ module ActivePublisher
2
2
  module Async
3
3
  module InMemoryAdapter
4
4
  class AsyncQueue
5
+ # These strategies are used to determine what to do with messages when the queue is full.
6
+ # :raise - Raise an error and drop the message.
7
+ # :drop - Silently drop the message.
8
+ # :wait - Wait for space in the queue to become available.
9
+ BACK_PRESSURE_STRATEGIES = [:raise, :drop, :wait].freeze
10
+
5
11
  include ::ActivePublisher::Logging
6
12
 
7
- attr_accessor :drop_messages_when_queue_full,
13
+ attr_accessor :back_pressure_strategy,
8
14
  :max_queue_size,
9
15
  :supervisor_interval
10
16
 
11
17
  attr_reader :consumer, :queue, :supervisor
12
18
 
13
- def initialize(drop_messages_when_queue_full, max_queue_size, supervisor_interval)
14
- @drop_messages_when_queue_full = drop_messages_when_queue_full
19
+ def initialize(back_pressure_strategy, max_queue_size, supervisor_interval)
20
+ self.back_pressure_strategy = back_pressure_strategy
15
21
  @max_queue_size = max_queue_size
16
22
  @supervisor_interval = supervisor_interval
17
23
  @queue = ::MultiOpQueue::Queue.new
18
24
  create_and_supervise_consumer!
19
25
  end
20
26
 
21
- def push(message)
22
- # default of 1_000_000 messages
23
- if queue.size > max_queue_size
24
- # Drop messages if the queue is full and we were configured to do so
25
- return if drop_messages_when_queue_full
27
+ def back_pressure_strategy=(strategy)
28
+ fail ::ArgumentError, "Invalid back pressure strategy: #{strategy}" unless BACK_PRESSURE_STRATEGIES.include?(strategy)
29
+ @back_pressure_strategy = strategy
30
+ end
26
31
 
27
- # By default we will raise an error to push the responsibility onto the caller
28
- fail ::ActivePublisher::Async::InMemoryAdapter::UnableToPersistMessageError, "Queue is full, messages will be dropped."
32
+ def push(message)
33
+ if queue.size >= max_queue_size
34
+ case back_pressure_strategy
35
+ when :drop
36
+ return
37
+ when :raise
38
+ fail ::ActivePublisher::Async::InMemoryAdapter::UnableToPersistMessageError, "Queue is full, messages will be dropped."
39
+ when :wait
40
+ # This is a really crappy way to wait
41
+ sleep 0.01 until queue.size < max_queue_size
42
+ end
29
43
  end
30
44
 
31
45
  queue.push(message)
@@ -1,3 +1,3 @@
1
1
  module ActivePublisher
2
- VERSION = "0.4.0"
2
+ VERSION = "1.0.0.pre0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_publisher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 1.0.0.pre0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Stien
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: exe
14
14
  cert_chain: []
15
- date: 2017-06-28 00:00:00.000000000 Z
15
+ date: 2017-08-28 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: bunny
@@ -145,12 +145,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
145
145
  version: '0'
146
146
  required_rubygems_version: !ruby/object:Gem::Requirement
147
147
  requirements:
148
- - - ">="
148
+ - - ">"
149
149
  - !ruby/object:Gem::Version
150
- version: '0'
150
+ version: 1.3.1
151
151
  requirements: []
152
152
  rubyforge_project:
153
- rubygems_version: 2.6.12
153
+ rubygems_version: 2.5.2
154
154
  signing_key:
155
155
  specification_version: 4
156
156
  summary: Aims to make publishing work across MRI and jRuby painless and add some nice