totoro 1.0.4 → 1.0.5

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
  SHA256:
3
- metadata.gz: 7f4c7f10ea818adbe2fa42308e54e93572e70a714d744e7e71429af98fd7dbcc
4
- data.tar.gz: 9168aa729f1f0aab8eb64da8b0475e9a272990d0ca7744b65f4fb5d70dcdeba3
3
+ metadata.gz: d5eec7c12e6dde49a945a21c48be6db1a773b28e1a1cceb5bc1dd8f63c741d15
4
+ data.tar.gz: 44c24808e0603cecdf0883a9df55681487830d48aecbc38ac8c8db6fac93666d
5
5
  SHA512:
6
- metadata.gz: a00e4ebd5d2eb76ff624e8fdf7ceda3aaa4a3f50484651d74f1b63ab3bc5163212e85cd0cce0039d6678b827df86468c598d4277bd70b8c29982f32e6c7e911a
7
- data.tar.gz: 518fd37374c5fbff31b67ecadc1a2a3bd96de078de5811e6abee644dcceb7f906380809b710ed50bcd8925d2a2596265d242749ed2d491f197cd566bd0e36cf1
6
+ metadata.gz: c6c8e432b961bc807045d60587983aae53e663ec8e9b78d0e92f8c3c1aa09dc583574a06a3b14c220eb573971145010940bb90e521dacd0b17bd35004738f22d
7
+ data.tar.gz: 067b6429ee06870dc084f4671c7581c81223d9219b6e46359e68b11545329a78a154d6b62402db99ad1e8f2bf5f386736686a010c033244f0663404dbc35c28a
data/README.md CHANGED
@@ -28,6 +28,11 @@ This command will generate two files
28
28
  2. `initilizers/totoro.rb` (Rails initializer)
29
29
  3. `db/migrate/[tiemstamp]_create_totoro_failed_messages.rb` (DB migration to create messages caching table)
30
30
 
31
+ #### if you havn't install gem delayed_jobs, then run initialization scripts
32
+ ```
33
+ rails g delayed_job:active_record
34
+ ```
35
+
31
36
  #### Run DB migraion
32
37
  `rake db:migrate`
33
38
 
@@ -1,15 +1,16 @@
1
1
  default: &default
2
- default:
3
- connect:
4
- host: rabbitmq
5
- port: 5672
6
- user: app
7
- pass: app
8
- queue:
9
- example_queue:
10
- name: real.queue.name
11
- durable: true
12
- clean_start: false
2
+ connect:
3
+ host: rabbitmq
4
+ port: 5672
5
+ user: app
6
+ pass: app
7
+ queue:
8
+ example_queue:
9
+ name: real.queue.name
10
+ durable: true
11
+ clean_start: false
12
+ manual_ack: true
13
+ force_ack: true
13
14
 
14
15
  custom:
15
16
  connect:
@@ -26,6 +26,9 @@ module Totoro
26
26
  payload_hash = JSON.parse(payload).with_indifferent_access
27
27
  process(payload_hash, metadata, delivery_info)
28
28
  end
29
+
30
+ handle_usr1_n_usr2
31
+
29
32
  subscribe_service.channel.work_pool.join
30
33
  rescue SignalException
31
34
  puts 'Terminating process ..'
@@ -37,6 +40,16 @@ module Totoro
37
40
 
38
41
  private
39
42
 
43
+ def handle_usr1_n_usr2
44
+ %w[USR1 USR2].each do |signal|
45
+ Signal.trap(signal) do
46
+ puts "#{signal} received."
47
+ handler = "on_#{signal.downcase}"
48
+ send handler if respond_to?(handler)
49
+ end
50
+ end
51
+ end
52
+
40
53
  def config
41
54
  @config ||= Totoro::Config.new(@prefix)
42
55
  end
@@ -23,8 +23,16 @@ module Totoro
23
23
  @data[:queue][queue_id][:exchange]
24
24
  end
25
25
 
26
- def clean_start?
27
- @data[:queue][id][:clean_start]
26
+ def clean_start?(id)
27
+ !!@data[:queue][id][:clean_start]
28
+ end
29
+
30
+ def manual_ack?(id)
31
+ !!@data[:queue][id][:manual_ack]
32
+ end
33
+
34
+ def force_ack?(id)
35
+ manual_ack?(id) && !!@data[:queue][id][:force_ack]
28
36
  end
29
37
 
30
38
  def queue(id)
@@ -8,9 +8,11 @@ module Totoro
8
8
 
9
9
  def subscribe(id)
10
10
  queue = bind_queue(id)
11
- queue.purge if @config.clean_start?
12
- queue.subscribe do |delivery_info, metadata, payload|
11
+ queue.purge if @config.clean_start?(id)
12
+ queue.subscribe(manual_ack: @config.manual_ack?(id)) do |delivery_info, metadata, payload|
13
13
  yield(delivery_info, metadata, payload)
14
+ ensure
15
+ channel.ack(delivery_info.delivery_tag) if @config.force_ack?(id)
14
16
  end
15
17
  end
16
18
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Totoro
4
- VERSION = '1.0.4'
4
+ VERSION = '1.0.5'
5
5
  end
Binary file
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: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - BlockchainTech
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-14 00:00:00.000000000 Z
11
+ date: 2019-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bunny
@@ -139,6 +139,7 @@ files:
139
139
  - lib/totoro/tasks/resend_message.rake
140
140
  - lib/totoro/utils.rb
141
141
  - lib/totoro/version.rb
142
+ - pkg/totoro-1.0.4.gem
142
143
  - spec/spec_helper.rb
143
144
  - spec/totoro_spec.rb
144
145
  - test/rabbitmq_commands.txt