totoro 0.6.0 → 0.6.1
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/lib/totoro/base_queue.rb +13 -12
- data/lib/totoro/version.rb +1 -1
- data/pkg/totoro-0.6.0.gem +0 -0
- data/test/rabbitmq_commands.txt +6 -0
- data/test/totoro_test/Gemfile.lock +1 -1
- data/test/totoro_test/app/services/bench_mark.txt +7 -0
- data/test/totoro_test/app/services/load_test.rb +19 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa6dd8c493beb2f3161254c4d0c207969183d3cbe0da84dc8782c63acba3f073
|
4
|
+
data.tar.gz: 50e0437780093c06a2c928b49fff7c8d09a094cf906a5c9ea4cd6cf54a070132
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '08d3b721c6d06504d37d6ebf153377df3354e446d79852b090e1d93920eb301fbb65cf925eba8adf10d1c0303e44230e91d5bdb89418f6e186f40b0b4ca716b0'
|
7
|
+
data.tar.gz: 883d9a3d0ceabd7bff3a1eebe6eda1b9700f384dea8895fa2ba628d36c587d5a29f365d8a43f5dffd8b85796f2eb1f9515fd8a5767bb81ff38beedadd83f22a4
|
data/lib/totoro/base_queue.rb
CHANGED
@@ -13,27 +13,21 @@ module Totoro
|
|
13
13
|
@connection ||= Bunny.new(config.connect.merge(threaded: false)).tap(&:start)
|
14
14
|
end
|
15
15
|
|
16
|
-
def channel
|
17
|
-
@channel ||= connection.create_channel
|
18
|
-
end
|
19
|
-
|
20
16
|
def subscribe_channel
|
21
17
|
@subscribe_channel ||= Bunny.new(config.connect).tap(&:start).create_channel
|
22
18
|
end
|
23
19
|
|
24
|
-
def exchange
|
25
|
-
@exchange ||= channel.default_exchange
|
26
|
-
end
|
27
|
-
|
28
|
-
# enqueue = publish to direct exchange
|
29
20
|
def enqueue(id, payload)
|
30
|
-
|
21
|
+
channel = connection.create_channel
|
22
|
+
queue = channel.queue(*config.queue(id))
|
31
23
|
payload = JSON.dump payload
|
32
|
-
|
24
|
+
channel.default_exchange.publish(payload, routing_key: queue.name)
|
33
25
|
Rails.logger.info "send message to #{queue.name}"
|
34
26
|
STDOUT.flush
|
27
|
+
channel.close
|
35
28
|
rescue Bunny::TCPConnectionFailedForAllHosts,
|
36
29
|
Bunny::NetworkErrorWrapper,
|
30
|
+
Bunny::ChannelAlreadyClosed,
|
37
31
|
AMQ::Protocol::EmptyResponseError => error
|
38
32
|
handle_failed_msg(id, payload, error)
|
39
33
|
end
|
@@ -55,13 +49,20 @@ module Totoro
|
|
55
49
|
Rails.logger.error error.message
|
56
50
|
Rails.logger.info 'Add failed message to resend list'
|
57
51
|
STDOUT.flush
|
58
|
-
|
52
|
+
clear_connection
|
59
53
|
Totoro::TotoroFailedMessage.create(
|
60
54
|
class_name: to_s,
|
61
55
|
queue_id: id,
|
62
56
|
payload: payload
|
63
57
|
)
|
64
58
|
end
|
59
|
+
|
60
|
+
def clear_connection
|
61
|
+
@exchange = nil
|
62
|
+
@channel = nil
|
63
|
+
@subscribe_channel = nil
|
64
|
+
@connection = nil
|
65
|
+
end
|
65
66
|
end
|
66
67
|
end
|
67
68
|
end
|
data/lib/totoro/version.rb
CHANGED
Binary file
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class LoadTest
|
2
|
+
def test_with_channel
|
3
|
+
start_time = Time.now
|
4
|
+
for i in 0..1000
|
5
|
+
Totoro::Queue.enqueue_with_new_channel('example_queue', {shu: i})
|
6
|
+
end
|
7
|
+
end_time = Time.now
|
8
|
+
p (end_time - start_time)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_without_channel
|
12
|
+
start_time = Time.now
|
13
|
+
for i in 0..1000
|
14
|
+
Totoro::Queue.enqueue('example_queue', {shu: i})
|
15
|
+
end
|
16
|
+
end_time = Time.now
|
17
|
+
p (end_time - start_time)
|
18
|
+
end
|
19
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: totoro
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ShuHui18
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-11-
|
11
|
+
date: 2018-11-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bunny
|
@@ -131,8 +131,10 @@ files:
|
|
131
131
|
- lib/totoro/tasks/resend_message.rake
|
132
132
|
- lib/totoro/totoro_failed_message.rb
|
133
133
|
- lib/totoro/version.rb
|
134
|
+
- pkg/totoro-0.6.0.gem
|
134
135
|
- spec/spec_helper.rb
|
135
136
|
- spec/totoro_spec.rb
|
137
|
+
- test/rabbitmq_commands.txt
|
136
138
|
- test/totoro_test/Gemfile
|
137
139
|
- test/totoro_test/Gemfile.lock
|
138
140
|
- test/totoro_test/README.md
|
@@ -144,6 +146,8 @@ files:
|
|
144
146
|
- test/totoro_test/app/mailers/application_mailer.rb
|
145
147
|
- test/totoro_test/app/models/application_record.rb
|
146
148
|
- test/totoro_test/app/models/worker/example_queue.rb
|
149
|
+
- test/totoro_test/app/services/bench_mark.txt
|
150
|
+
- test/totoro_test/app/services/load_test.rb
|
147
151
|
- test/totoro_test/app/views/layouts/mailer.html.erb
|
148
152
|
- test/totoro_test/app/views/layouts/mailer.text.erb
|
149
153
|
- test/totoro_test/bin/bundle
|