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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 85630904511993ae3171f7e70b5c8fdec2f973c9ba79de099bd9b2ff897def24
4
- data.tar.gz: a3d79f5cc3a21c193c0e14acc119d971f2dbcc20e2e0cd7044c716f067edf16d
3
+ metadata.gz: aa6dd8c493beb2f3161254c4d0c207969183d3cbe0da84dc8782c63acba3f073
4
+ data.tar.gz: 50e0437780093c06a2c928b49fff7c8d09a094cf906a5c9ea4cd6cf54a070132
5
5
  SHA512:
6
- metadata.gz: dc738f3bf93be2be9d7030668c48dec8f7b43f3230cc7c4cfac5803cfeb357b4cefe81fe22da9391cce9f07e0c99511707f05b63cfc3303173a3df9f8c86e943
7
- data.tar.gz: 1d7a10ef164c84bc2b69165e52fdfd0b59a1e319e73e2fc4dcf804559d7d437949bff4bab6240f4c5c842b2d25c2fce097fd24a749e431ab9922d2f2476e3e13
6
+ metadata.gz: '08d3b721c6d06504d37d6ebf153377df3354e446d79852b090e1d93920eb301fbb65cf925eba8adf10d1c0303e44230e91d5bdb89418f6e186f40b0b4ca716b0'
7
+ data.tar.gz: 883d9a3d0ceabd7bff3a1eebe6eda1b9700f384dea8895fa2ba628d36c587d5a29f365d8a43f5dffd8b85796f2eb1f9515fd8a5767bb81ff38beedadd83f22a4
@@ -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
- queue = channel.queue(*config.queue(id))
21
+ channel = connection.create_channel
22
+ queue = channel.queue(*config.queue(id))
31
23
  payload = JSON.dump payload
32
- exchange.publish(payload, routing_key: queue.name)
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
- @connection = nil
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Totoro
4
- VERSION = '0.6.0'
4
+ VERSION = '0.6.1'
5
5
  end
Binary file
@@ -0,0 +1,6 @@
1
+
2
+ rabbitmqctl set_permissions -p / hui '.*' '.*' '.*'
3
+ rabbitmqctl clear_permissions -p / hui
4
+ rabbitmqctl close_all_connections "changed_user_permissions"
5
+
6
+ Totoro::Queue.enqueue('example_queue', {shu: 123})
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /totoro
3
3
  specs:
4
- totoro (0.5.7)
4
+ totoro (0.6.0)
5
5
  bunny (~> 2.10)
6
6
  delayed_job_active_record (~> 4.1.3)
7
7
  delayed_job_recurring (~> 0.3.7)
@@ -0,0 +1,7 @@
1
+ with out put
2
+ 1000
3
+ 1.0696876
4
+ 9.3701257
5
+ 10000
6
+ 10.0278923
7
+ 85.1188306
@@ -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.0
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-06 00:00:00.000000000 Z
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