eventhub-processor2 1.8.0 → 1.9.0

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: ada51c14b34969eea52b154ed1aad5d6d5114354aeab4f3f4ef5a43269f6d3ca
4
- data.tar.gz: 90c9e9dd2af39915a9f7d7f81e12f260b0a9206ef6fb76c080e7406eb8d2b9d0
3
+ metadata.gz: c2802cc49773eefcd1c4ac043ad25c07a59576eae96f1a657556741e20da1815
4
+ data.tar.gz: 84f36939159674c30169766b44e427fdee7a03cbdba0f3d4f356040bb5c2ed41
5
5
  SHA512:
6
- metadata.gz: 4fc3467735769496ead9fbcd560e8f9085cf79f599738a201042515de769b6b51b00b0c8662f774fd488cfb152c326cf1361e54ad3148517cf9daeb95ec5e9c1
7
- data.tar.gz: f5a4bb8365be33644b5140de210cdc372ca9ff61b15b69ad33a5efb3c17e57e5e8870f4f5d8fd9cf4ee5957e5b2758f22587fa3a07c4d845d3cabcdd0f49776f
6
+ metadata.gz: 71c2532c9d70ea9d913778f12435f36d8d4aa1185b7586e6ad41803aa2f5f4182c720edaa17e32e77889c9e46ab4b4147fbaae78ec7ecfab31729208e4f182ed
7
+ data.tar.gz: 57e0722d7267a3dd6356422ac7f069390dcfce6fe06f7d40eac1debba3efb44418d1c3a5291806db7d4bf0272e98a54a5dc5a479ab1c621ee8afdf33e3f09241
data/.rspec CHANGED
@@ -1,2 +1,3 @@
1
+ --format documentation
1
2
  --color
2
3
  --require spec_helper
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.7.0
1
+ 2.6.6
data/.travis.yml CHANGED
@@ -9,10 +9,10 @@ os:
9
9
  - linux
10
10
 
11
11
  rvm:
12
- - 2.7.1
12
+ - 3.0.0
13
+ - 2.7.2
13
14
  - 2.6.6
14
15
  - 2.5.8
15
- - 2.4.10
16
16
 
17
17
  env:
18
18
  - secure: R0rBtWClmnJKO+zyAncF6+1qDpZ6JQR+Z6VXzUmWw8MuxUXv732XTNYulY/tTeDW876GofAsOF9QfX/jhF+2ubV8SzM6rKTZS09feATuOWRPtECEaBOPcb0JGYouBNg/Lv4onuXb8KS/9U093sRqiJMfib82iY7QK9bnDPsYoQXtMnI7KBeQNrTV0H4nby3lvbjcpMDhmyg+anOmCP5yepZeS53Qq+C5GHguYivisvhSPmCfONrT303XxFLDo/aOkMDlceeZBDhtcpm5Px3GIwybSI9xRtAnpT73oL1Piazda6mRN7VHoT7YAHKqcJNZDB48HYuTj3Pt3oVVw0v78Cf25caBqXttXflXfB8U3qfVt+94uF0icH34NAnpW9l1B8GXHi6CTr27Hg2ZatWkQCN1rCpcCaW0eM/NoAG6snwTIwr1VvjLWpSW5wwhQgHPyMl+MRlTmCn/UM+eQSwPVhflKpMS1+ah6cbhDrQQF1jDt3dRaLqSnVE4APrafdT90SA3SCG2MGOE+pp+DX528gEsRB34UdX2V67dlwXeRu1eU5vZBR7jZrqwuwTAgSvxEF0eJWC0kgvEfouzuVHhVmmSAcNNHlg2kd0/oyQELyXTsklJghwAupcy4X/GEAyfLW9GAxItjATyV7XyfjmaBmdzHl/5JWeXicoyZ/4+8iE=
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog of EventHub::Processor2
2
2
 
3
+ ## 1.9.0 / 2021-02-26
4
+
5
+ * Updated gem dependencies
6
+ * Appply ruby style guides
7
+ * Reduce log noice
8
+
3
9
  ## 1.8.0 / 2020-05-05
4
10
 
5
11
  * Increase watchdog cycle time to 60s
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
3
  git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
4
 
data/Gemfile.lock CHANGED
@@ -1,62 +1,77 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- eventhub-processor2 (1.8.0)
4
+ eventhub-processor2 (1.9.0)
5
5
  bunny (~> 2.15)
6
- celluloid (~> 0.17)
6
+ celluloid (~> 0.18)
7
7
  eventhub-components (~> 0.2)
8
8
  uuidtools (~> 2.1)
9
9
 
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
- amq-protocol (2.3.1)
14
- bunny (2.15.0)
13
+ amq-protocol (2.3.2)
14
+ ast (2.4.2)
15
+ bunny (2.17.0)
15
16
  amq-protocol (~> 2.3, >= 2.3.1)
16
- celluloid (0.17.4)
17
- celluloid-essentials
18
- celluloid-extras
19
- celluloid-fsm
20
- celluloid-pool
21
- celluloid-supervision
22
- timers (>= 4.1.1)
23
- celluloid-essentials (0.20.5)
24
- timers (>= 4.1.1)
25
- celluloid-extras (0.20.5)
26
- timers (>= 4.1.1)
27
- celluloid-fsm (0.20.5)
28
- timers (>= 4.1.1)
29
- celluloid-pool (0.20.5)
30
- timers (>= 4.1.1)
31
- celluloid-supervision (0.20.6)
32
- timers (>= 4.1.1)
33
- diff-lcs (1.3)
34
- docile (1.3.2)
17
+ celluloid (0.18.0)
18
+ timers (~> 4)
19
+ diff-lcs (1.4.4)
20
+ docile (1.3.5)
35
21
  eventhub-components (0.2.2)
36
22
  logstash-logger (~> 0.26)
37
23
  logstash-event (1.2.02)
38
24
  logstash-logger (0.26.1)
39
25
  logstash-event (~> 1.2)
40
- rake (13.0.1)
41
- rspec (3.9.0)
42
- rspec-core (~> 3.9.0)
43
- rspec-expectations (~> 3.9.0)
44
- rspec-mocks (~> 3.9.0)
45
- rspec-core (3.9.2)
46
- rspec-support (~> 3.9.3)
47
- rspec-expectations (3.9.1)
26
+ parallel (1.20.1)
27
+ parser (3.0.0.0)
28
+ ast (~> 2.4.1)
29
+ rainbow (3.0.0)
30
+ rake (13.0.3)
31
+ regexp_parser (2.0.3)
32
+ rexml (3.2.4)
33
+ rspec (3.10.0)
34
+ rspec-core (~> 3.10.0)
35
+ rspec-expectations (~> 3.10.0)
36
+ rspec-mocks (~> 3.10.0)
37
+ rspec-core (3.10.1)
38
+ rspec-support (~> 3.10.0)
39
+ rspec-expectations (3.10.1)
48
40
  diff-lcs (>= 1.2.0, < 2.0)
49
- rspec-support (~> 3.9.0)
50
- rspec-mocks (3.9.1)
41
+ rspec-support (~> 3.10.0)
42
+ rspec-mocks (3.10.2)
51
43
  diff-lcs (>= 1.2.0, < 2.0)
52
- rspec-support (~> 3.9.0)
53
- rspec-support (3.9.3)
54
- simplecov (0.18.5)
44
+ rspec-support (~> 3.10.0)
45
+ rspec-support (3.10.2)
46
+ rubocop (1.10.0)
47
+ parallel (~> 1.10)
48
+ parser (>= 3.0.0.0)
49
+ rainbow (>= 2.2.2, < 4.0)
50
+ regexp_parser (>= 1.8, < 3.0)
51
+ rexml
52
+ rubocop-ast (>= 1.2.0, < 2.0)
53
+ ruby-progressbar (~> 1.7)
54
+ unicode-display_width (>= 1.4.0, < 3.0)
55
+ rubocop-ast (1.4.1)
56
+ parser (>= 2.7.1.5)
57
+ rubocop-performance (1.9.2)
58
+ rubocop (>= 0.90.0, < 2.0)
59
+ rubocop-ast (>= 0.4.0)
60
+ ruby-progressbar (1.11.0)
61
+ simplecov (0.21.2)
55
62
  docile (~> 1.1)
56
63
  simplecov-html (~> 0.11)
57
- simplecov-html (0.12.2)
58
- timers (4.3.0)
59
- uuidtools (2.1.5)
64
+ simplecov_json_formatter (~> 0.1)
65
+ simplecov-html (0.12.3)
66
+ simplecov_json_formatter (0.1.2)
67
+ standard (0.13.0)
68
+ rubocop (= 1.10.0)
69
+ rubocop-performance (= 1.9.2)
70
+ standardrb (1.0.0)
71
+ standard
72
+ timers (4.3.3)
73
+ unicode-display_width (2.0.0)
74
+ uuidtools (2.2.0)
60
75
 
61
76
  PLATFORMS
62
77
  ruby
@@ -66,7 +81,8 @@ DEPENDENCIES
66
81
  eventhub-processor2!
67
82
  rake (~> 13.0)
68
83
  rspec (~> 3.9)
69
- simplecov (~> 0.18)
84
+ simplecov (~> 0.21)
85
+ standardrb (~> 1.0)
70
86
 
71
87
  BUNDLED WITH
72
- 2.1.2
88
+ 2.1.4
data/Rakefile CHANGED
@@ -1,6 +1,9 @@
1
- require 'bundler/gem_tasks'
2
- require 'rspec/core/rake_task'
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+ require "standard/rake"
3
4
 
4
- RSpec::Core::RakeTask.new(:spec)
5
+ RSpec::Core::RakeTask.new(:spec) do |t|
6
+ t.verbose = false
7
+ end
5
8
 
6
- task default: :spec
9
+ task default: [:spec, :standard]
data/docker/Dockerfile CHANGED
@@ -1,4 +1,4 @@
1
- FROM rabbitmq:3.8.2-management
1
+ FROM rabbitmq:3.8.12-management
2
2
 
3
3
  LABEL maintainer="thomas.steiner@ikey.ch"
4
4
 
@@ -4,7 +4,7 @@ services:
4
4
  rabbitmq:
5
5
  build: .
6
6
  container_name: eventhub.rabbitmq
7
- image: eventhub.rabbitmq:3.8.2
7
+ image: eventhub.rabbitmq:3.8.12
8
8
  ports:
9
9
  - "5672:5672"
10
10
  - "15672:15672"
@@ -1,37 +1,38 @@
1
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path("../lib", __FILE__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require 'eventhub/version'
3
+ require "eventhub/version"
4
4
 
5
- note = 'Next generation gem to build ruby based eventhub processor'
5
+ note = "Next generation gem to build ruby based eventhub processor"
6
6
 
7
7
  Gem::Specification.new do |spec|
8
- spec.name = 'eventhub-processor2'
9
- spec.version = EventHub::VERSION
10
- spec.authors = ['Steiner, Thomas']
11
- spec.email = ['thomas.steiner@ikey.ch']
8
+ spec.name = "eventhub-processor2"
9
+ spec.version = EventHub::VERSION
10
+ spec.authors = ["Steiner, Thomas"]
11
+ spec.email = ["thomas.steiner@ikey.ch"]
12
12
 
13
- spec.summary = note
14
- spec.description = note
15
- spec.homepage = 'https://github.com/thomis/eventhub-processor2'
16
- spec.license = 'MIT'
13
+ spec.summary = note
14
+ spec.description = note
15
+ spec.homepage = "https://github.com/thomis/eventhub-processor2"
16
+ spec.license = "MIT"
17
17
 
18
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
19
19
  f.match(%r{^(test|spec|features)/})
20
20
  end
21
- spec.bindir = 'exe'
22
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
- spec.require_paths = ['lib']
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
24
 
25
25
  # required by celluloid and bunny (-> amq-protocol)
26
26
  # spec.required_ruby_version = '~> 2.2.6'
27
27
 
28
- spec.add_dependency 'celluloid', '~> 0.17'
29
- spec.add_dependency 'bunny', '~> 2.15'
30
- spec.add_dependency 'eventhub-components', '~> 0.2'
31
- spec.add_dependency 'uuidtools', '~> 2.1'
28
+ spec.add_dependency "celluloid", "~> 0.18"
29
+ spec.add_dependency "bunny", "~> 2.15"
30
+ spec.add_dependency "eventhub-components", "~> 0.2"
31
+ spec.add_dependency "uuidtools", "~> 2.1"
32
32
 
33
- spec.add_development_dependency 'bundler', '~> 2.1'
34
- spec.add_development_dependency 'rake', '~> 13.0'
35
- spec.add_development_dependency 'rspec', '~> 3.9'
36
- spec.add_development_dependency 'simplecov', '~> 0.18'
33
+ spec.add_development_dependency "bundler", "~> 2.1"
34
+ spec.add_development_dependency "rake", "~> 13.0"
35
+ spec.add_development_dependency "rspec", "~> 3.9"
36
+ spec.add_development_dependency "simplecov", "~> 0.21"
37
+ spec.add_development_dependency "standardrb", "~> 1.0"
37
38
  end
data/example/crasher.rb CHANGED
@@ -1,17 +1,17 @@
1
- require 'eventhub/components'
2
- require_relative '../lib/eventhub/sleeper'
1
+ require "eventhub/components"
2
+ require_relative "../lib/eventhub/sleeper"
3
3
 
4
4
  RESTART_RANGES_IN_SECONDS = (30..600).to_a
5
- PROCESS_PATTERNS = ['router', 'receiver']
5
+ PROCESS_PATTERNS = ["router", "receiver"]
6
6
 
7
7
  # Module Crasher
8
8
  module Crasher
9
9
  def self.logger
10
10
  unless @logger
11
11
  @logger = ::EventHub::Components::MultiLogger.new
12
- @logger.add_device(Logger.new(STDOUT))
12
+ @logger.add_device(Logger.new($stdout))
13
13
  @logger.add_device(
14
- EventHub::Components::Logger.logstash('crasher', 'development')
14
+ EventHub::Components::Logger.logstash("crasher", "development")
15
15
  )
16
16
  end
17
17
  @logger
@@ -26,7 +26,7 @@ module Crasher
26
26
 
27
27
  def restart
28
28
  Crasher.logger.info "Sending Signal HUP to process [#{@id}/#{@name}]"
29
- Process.kill('HUP', @id)
29
+ Process.kill("HUP", @id)
30
30
  rescue Errno::ESRCH
31
31
  end
32
32
 
@@ -35,13 +35,13 @@ module Crasher
35
35
  PROCESS_PATTERNS.each do |name|
36
36
  data = `ps | grep #{name}.rb`
37
37
  data.lines[0..-2].each do |line|
38
- a = line.split(' ')
38
+ a = line.split(" ")
39
39
  next if a.size > 5
40
40
  processes << MyProcess.new(a[0].to_i, a[-1])
41
41
  end
42
42
  end
43
43
 
44
- Crasher.logger.info "Found ids: #{processes.map{ |pr| pr.id}.join(', ')}"
44
+ Crasher.logger.info "Found ids: #{processes.map { |pr| pr.id }.join(", ")}"
45
45
  processes
46
46
  end
47
47
  end
@@ -61,13 +61,12 @@ module Crasher
61
61
  end
62
62
  end
63
63
 
64
-
65
64
  class Application
66
65
  def initialize
67
66
  @sleeper = EventHub::Sleeper.new
68
67
  @run = true
69
68
 
70
- Signal.trap('INT') {
69
+ Signal.trap("INT") {
71
70
  @run = false
72
71
  @sleeper.stop
73
72
  }
@@ -75,8 +74,8 @@ module Crasher
75
74
 
76
75
  def pick_process
77
76
  processes = []
78
- processes << Docker.new('processor-rabbitmq')
79
- processes << Docker.new('processor-rabbitmq', 0)
77
+ processes << Docker.new("eventhub.rabbitmq")
78
+ processes << Docker.new("eventhub.rabbitmq", 0)
80
79
  processes << MyProcess.all
81
80
  processes.flatten.sample
82
81
  end
@@ -89,7 +88,7 @@ module Crasher
89
88
  @sleeper.start(to_sleep)
90
89
  next unless @run
91
90
  process = pick_process
92
- process.restart if process
91
+ process&.restart
93
92
  end
94
93
  Crasher.logger.info "Crasher has been stopped"
95
94
  end
data/example/publisher.rb CHANGED
@@ -1,9 +1,9 @@
1
- require 'bunny'
2
- require 'celluloid/current'
3
- require 'json'
4
- require 'securerandom'
5
- require 'eventhub/components'
6
- require_relative '../lib/eventhub/sleeper'
1
+ require "bunny"
2
+ require "celluloid"
3
+ require "json"
4
+ require "securerandom"
5
+ require "eventhub/components"
6
+ require_relative "../lib/eventhub/sleeper"
7
7
 
8
8
  SIGNALS_FOR_TERMINATION = [:INT, :TERM, :QUIT]
9
9
  SIGNALS_FOR_RELOAD_CONFIG = [:HUP]
@@ -12,16 +12,16 @@ PAUSE_BETWEEN_WORK = 0.05 # default is 0.05
12
12
 
13
13
  Celluloid.logger = nil
14
14
  Celluloid.exception_handler { |ex| Publisher.logger.error "Exception occured: #{ex}}" }
15
+ Celluloid.boot
15
16
 
16
17
  # Publisher module
17
18
  module Publisher
18
-
19
19
  def self.logger
20
20
  unless @logger
21
21
  @logger = ::EventHub::Components::MultiLogger.new
22
- @logger.add_device(Logger.new(STDOUT))
22
+ @logger.add_device(Logger.new($stdout))
23
23
  @logger.add_device(
24
- EventHub::Components::Logger.logstash('publisher', 'development')
24
+ EventHub::Components::Logger.logstash("publisher", "development")
25
25
  )
26
26
  end
27
27
  @logger
@@ -36,11 +36,11 @@ module Publisher
36
36
  @start = Time.now
37
37
  @files_sent = 0
38
38
 
39
- @filename = 'data/store.json'
39
+ @filename = "data/store.json"
40
40
  if File.exist?(@filename)
41
41
  cleanup
42
42
  else
43
- File.write(@filename, '{}')
43
+ File.write(@filename, "{}")
44
44
  end
45
45
 
46
46
  every(30) { write_statistics }
@@ -48,7 +48,7 @@ module Publisher
48
48
 
49
49
  def start(name)
50
50
  store = read_store
51
- store[name] = Time.now.strftime('%Y-%m-%d %H:%M:%S.%L')
51
+ store[name] = Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")
52
52
  write_store(store)
53
53
  end
54
54
 
@@ -76,19 +76,20 @@ module Publisher
76
76
 
77
77
  def write_statistics
78
78
  now = Time.now
79
- rate = @files_sent / (now-@start)
80
- time_spent = (now-@start)/60
81
- Publisher.logger.info("Started @ #{@start.strftime('%Y-%m-%d %H:%M:%S.%L')}: Files sent within #{'%0.1f' % time_spent} minutes: #{@files_sent}, #{ '%0.1f' % rate} files/second")
79
+ rate = @files_sent / (now - @start)
80
+ time_spent = (now - @start) / 60
81
+ Publisher.logger.info("Started @ #{@start.strftime("%Y-%m-%d %H:%M:%S.%L")}: Files sent within #{"%0.1f" % time_spent} minutes: #{@files_sent}, #{"%0.1f" % rate} files/second")
82
82
  end
83
83
 
84
84
  private
85
- def read_store
86
- JSON.parse(File.read(@filename))
87
- end
88
85
 
89
- def write_store(store)
90
- File.write(@filename, store.to_json)
91
- end
86
+ def read_store
87
+ JSON.parse(File.read(@filename))
88
+ end
89
+
90
+ def write_store(store)
91
+ File.write(@filename, store.to_json)
92
+ end
92
93
  end
93
94
 
94
95
  # Worker
@@ -106,26 +107,26 @@ module Publisher
106
107
  sleep PAUSE_BETWEEN_WORK
107
108
  end
108
109
  ensure
109
- @connection.close if @connection
110
+ @connection&.close
110
111
  end
111
112
 
112
113
  private
113
114
 
114
115
  def connect
115
- @connection = Bunny.new(vhost: 'event_hub',
116
+ @connection = Bunny.new(vhost: "event_hub",
116
117
  automatic_recovery: false,
117
- logger: Logger.new('/dev/null'))
118
+ logger: Logger.new("/dev/null"))
118
119
  @connection.start
119
120
  @channel = @connection.create_channel
120
121
  @channel.confirm_select
121
- @exchange = @channel.direct('example.outbound', durable: true)
122
+ @exchange = @channel.direct("example.outbound", durable: true)
122
123
  end
123
124
 
124
125
  def do_the_work
125
- #prepare id and content
126
+ # prepare id and content
126
127
  id = SecureRandom.uuid
127
128
  file_name = "data/#{id}.json"
128
- data = { body: { id: id } }.to_json
129
+ data = {body: {id: id}}.to_json
129
130
 
130
131
  # start transaction...
131
132
  Celluloid::Actor[:transaction_store].start(id)
@@ -135,10 +136,10 @@ module Publisher
135
136
  @exchange.publish(data, persistent: true)
136
137
  success = @channel.wait_for_confirms
137
138
  if success
138
- Celluloid::Actor[:transaction_store].stop(id) if Celluloid::Actor[:transaction_store]
139
- Publisher.logger.info("[#{id}] - Message sent")
139
+ Celluloid::Actor[:transaction_store]&.stop(id)
140
+ Publisher&.logger&.info("[#{id}] - Message sent")
140
141
  else
141
- Publisher.logger.error("[#{id}] - Published message not confirmed")
142
+ Publisher&.logger&.error("[#{id}] - Published message not confirmed")
142
143
  end
143
144
  end
144
145
  end
@@ -153,27 +154,27 @@ module Publisher
153
154
  def start_supervisor
154
155
  @config = Celluloid::Supervision::Configuration.define(
155
156
  [
156
- { type: TransactionStore, as: :transaction_store },
157
- { type: Worker, as: :worker }
157
+ {type: TransactionStore, as: :transaction_store},
158
+ {type: Worker, as: :worker}
158
159
  ]
159
160
  )
160
161
 
161
162
  sleeper = @sleeper
162
163
  @config.injection!(:before_restart, proc do
163
- Publisher.logger.info('Restarting in 15 seconds...')
164
+ Publisher.logger.info("Restarting in 15 seconds...")
164
165
  sleeper.start(15)
165
166
  end)
166
167
  @config.deploy
167
168
  end
168
169
 
169
170
  def start
170
- Publisher.logger.info 'Publisher has been started'
171
+ Publisher.logger.info "Publisher has been started"
171
172
 
172
173
  setup_signal_handler
173
174
  start_supervisor
174
175
  main_event_loop
175
176
 
176
- Publisher.logger.info 'Publisher has been stopped'
177
+ Publisher.logger.info "Publisher has been stopped"
177
178
  end
178
179
 
179
180
  private
@@ -181,12 +182,11 @@ module Publisher
181
182
  def main_event_loop
182
183
  loop do
183
184
  command = @command_queue.pop
184
- case
185
- when SIGNALS_FOR_TERMINATION.include?(command)
186
- @sleeper.stop
187
- break
188
- else
189
- sleep 0.5
185
+ if SIGNALS_FOR_TERMINATION.include?(command)
186
+ @sleeper.stop
187
+ break
188
+ else
189
+ sleep 0.5
190
190
  end
191
191
  end
192
192