toiler 0.5.1.pre7 → 0.5.1.pre9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +6 -6
- data/lib/toiler/actor/fetcher.rb +9 -2
- data/lib/toiler/actor/processor.rb +3 -2
- data/lib/toiler/version.rb +1 -1
- data/spec/models/fetcher_spec.rb +3 -1
- data/spec/models/processor_spec.rb +0 -1
- data/spec/models/supervisor_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61292f1454428dae50787cb722201108250b136b
|
4
|
+
data.tar.gz: 004ab4f17d203ca40b4f4f74fac79ba52f0449cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9a8db8fcfd8c5986cf096a4d8f598bdef0a8a35f8da739fdecce50f6dc8976a822cd86f6f5caf8ad4d3d51257eb4fc5591dca29a8b91acc42978af8451711b5
|
7
|
+
data.tar.gz: 1c2552b393d6fde181b4d81fa80a971aa8f2076c44f3f556da2957a9453a5d13df8abaa0a1f90facc097a072592646033f4391682a12756001a5e38c736e2063
|
data/Gemfile.lock
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
toiler (0.
|
5
|
-
aws-sdk-sqs (
|
4
|
+
toiler (0.5.1.pre7)
|
5
|
+
aws-sdk-sqs (>= 1.0.0, < 2.0.0)
|
6
6
|
concurrent-ruby (~> 1.0, >= 1.0.0)
|
7
7
|
concurrent-ruby-edge (~> 0.3, >= 0.3)
|
8
8
|
|
@@ -11,14 +11,14 @@ GEM
|
|
11
11
|
specs:
|
12
12
|
ast (2.4.0)
|
13
13
|
aws-eventstream (1.0.1)
|
14
|
-
aws-partitions (1.
|
15
|
-
aws-sdk-core (3.
|
14
|
+
aws-partitions (1.105.0)
|
15
|
+
aws-sdk-core (3.31.0)
|
16
16
|
aws-eventstream (~> 1.0)
|
17
17
|
aws-partitions (~> 1.0)
|
18
18
|
aws-sigv4 (~> 1.0)
|
19
19
|
jmespath (~> 1.0)
|
20
|
-
aws-sdk-sqs (1.
|
21
|
-
aws-sdk-core (~> 3)
|
20
|
+
aws-sdk-sqs (1.7.0)
|
21
|
+
aws-sdk-core (~> 3, >= 3.26.0)
|
22
22
|
aws-sigv4 (~> 1.0)
|
23
23
|
aws-sigv4 (1.0.3)
|
24
24
|
concurrent-ruby (1.0.5)
|
data/lib/toiler/actor/fetcher.rb
CHANGED
@@ -10,7 +10,7 @@ module Toiler
|
|
10
10
|
FETCH_LIMIT = 10
|
11
11
|
|
12
12
|
attr_accessor :queue, :wait, :visibility_timeout, :free_processors,
|
13
|
-
:executing, :waiting_messages
|
13
|
+
:executing, :waiting_messages, :concurrency
|
14
14
|
|
15
15
|
def initialize(queue, client, count)
|
16
16
|
debug "Initializing Fetcher for queue #{queue}..."
|
@@ -21,6 +21,7 @@ module Toiler
|
|
21
21
|
@visibility_timeout = @queue.visibility_timeout
|
22
22
|
@executing = false
|
23
23
|
@waiting_messages = 0
|
24
|
+
@concurrency = count
|
24
25
|
debug "Finished initializing Fetcher for queue #{queue}"
|
25
26
|
tell :poll_messages
|
26
27
|
end
|
@@ -75,6 +76,8 @@ module Toiler
|
|
75
76
|
return unless should_poll?
|
76
77
|
|
77
78
|
max_number_of_messages = max_messages
|
79
|
+
return if waiting_messages > 0 && !full_batch?(max_number_of_messages)
|
80
|
+
|
78
81
|
@waiting_messages += max_number_of_messages
|
79
82
|
|
80
83
|
debug "Fetcher #{queue.name} polling messages..."
|
@@ -89,13 +92,17 @@ module Toiler
|
|
89
92
|
tell :poll_messages
|
90
93
|
end
|
91
94
|
|
92
|
-
|
95
|
+
poll_messages if should_poll?
|
93
96
|
end
|
94
97
|
|
95
98
|
def should_poll?
|
96
99
|
free_processors / 2 > waiting_messages
|
97
100
|
end
|
98
101
|
|
102
|
+
def full_batch?(max_number_of_messages)
|
103
|
+
max_number_of_messages == FETCH_LIMIT || max_number_of_messages >= concurrency * 0.1
|
104
|
+
end
|
105
|
+
|
99
106
|
def processor_pool
|
100
107
|
@processor_pool ||= Toiler.processor_pool queue.name
|
101
108
|
end
|
@@ -94,12 +94,13 @@ module Toiler
|
|
94
94
|
|
95
95
|
interval = [1, queue_visibility / 3].max
|
96
96
|
Concurrent::TimerTask.execute execution_interval: interval,
|
97
|
-
timeout_interval: interval do
|
97
|
+
timeout_interval: interval do |task|
|
98
98
|
begin
|
99
99
|
sqs_msg.visibility_timeout = queue_visibility
|
100
100
|
yield sqs_msg, body if block_given?
|
101
101
|
rescue StandardError => e
|
102
|
-
error "Processor #{queue} failed to extend visibility of message: #{e.message}\n#{e.backtrace.join("\n")}"
|
102
|
+
error "Processor #{queue} failed to extend visibility of message - #{e.class}: #{e.message}\n#{e.backtrace.join("\n")}"
|
103
|
+
task.shutdown if e.message.include?('ReceiptHandle is invalid')
|
103
104
|
end
|
104
105
|
end
|
105
106
|
end
|
data/lib/toiler/version.rb
CHANGED
data/spec/models/fetcher_spec.rb
CHANGED
@@ -7,13 +7,15 @@ RSpec.describe Toiler::Actor::Fetcher, type: :model do
|
|
7
7
|
|
8
8
|
before do
|
9
9
|
allow_any_instance_of(Toiler::Actor::Fetcher).to receive(:log).and_return(true)
|
10
|
+
allow_any_instance_of(Toiler::Actor::Fetcher).to receive(:tell)
|
10
11
|
allow_any_instance_of(Toiler::Aws::Queue).to receive(:visibility_timeout).and_return(100)
|
11
12
|
allow(client).to receive(:get_queue_url).with(queue_name: 'default').and_return double(:queue, queue_url: 'http://aws.fake/queue')
|
12
13
|
end
|
13
14
|
|
14
15
|
describe "#new" do
|
15
16
|
it 'completes sucessfully' do
|
16
|
-
fetcher = described_class.new(queue, client)
|
17
|
+
fetcher = described_class.new(queue, client, 1)
|
18
|
+
expect(fetcher).to have_received(:tell).with(:poll_messages)
|
17
19
|
expect(fetcher.executing?).to eq(false)
|
18
20
|
end
|
19
21
|
end
|
@@ -7,7 +7,6 @@ RSpec.describe Toiler::Actor::Processor, type: :model do
|
|
7
7
|
describe "#new" do
|
8
8
|
it 'initializes properly' do
|
9
9
|
allow(Toiler).to receive(:fetcher).and_return(fetcher)
|
10
|
-
expect(fetcher).to receive(:tell).with(:processor_finished)
|
11
10
|
processor = described_class.new('default')
|
12
11
|
expect(processor.executing?).to eq(false)
|
13
12
|
end
|
@@ -13,7 +13,7 @@ RSpec.describe Toiler::Actor::Supervisor, type: :model do
|
|
13
13
|
|
14
14
|
Toiler.options.merge!(active_queues: ['default'])
|
15
15
|
expect(::Aws::SQS::Client).to receive(:new).and_return(sqs_client)
|
16
|
-
expect(Toiler::Actor::Fetcher).to receive(:spawn!).with(name: :fetcher_default, supervise: true, args: ['default', sqs_client])
|
16
|
+
expect(Toiler::Actor::Fetcher).to receive(:spawn!).with(name: :fetcher_default, supervise: true, args: ['default', sqs_client, 1])
|
17
17
|
expect(Concurrent::Actor::Utils::Pool).to receive(:spawn!).with(:processor_pool_default, 1)
|
18
18
|
supervisor = described_class.new
|
19
19
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: toiler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.1.
|
4
|
+
version: 0.5.1.pre9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sebastian Schepens
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-10-
|
11
|
+
date: 2018-10-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|