legion-transport 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +7 -0
  2. data/.circleci/config.yml +116 -0
  3. data/.gitignore +13 -0
  4. data/.rubocop.yml +27 -0
  5. data/Gemfile +4 -0
  6. data/Rakefile +6 -0
  7. data/bin/console +14 -0
  8. data/bin/setup +8 -0
  9. data/bitbucket-pipelines.yml +24 -0
  10. data/legion-transport.gemspec +38 -0
  11. data/lib/legion/transport.rb +20 -0
  12. data/lib/legion/transport/common.rb +71 -0
  13. data/lib/legion/transport/connection.rb +18 -0
  14. data/lib/legion/transport/connections/bunny.rb +53 -0
  15. data/lib/legion/transport/connections/common.rb +36 -0
  16. data/lib/legion/transport/connections/marchhare.rb +20 -0
  17. data/lib/legion/transport/consumer.rb +6 -0
  18. data/lib/legion/transport/consumers/bunny.rb +11 -0
  19. data/lib/legion/transport/consumers/common.rb +8 -0
  20. data/lib/legion/transport/consumers/marchhare.rb +11 -0
  21. data/lib/legion/transport/exchange.rb +13 -0
  22. data/lib/legion/transport/exchanges/bunny.rb +28 -0
  23. data/lib/legion/transport/exchanges/common.rb +32 -0
  24. data/lib/legion/transport/exchanges/lex.rb +11 -0
  25. data/lib/legion/transport/exchanges/marchhare.rb +17 -0
  26. data/lib/legion/transport/exchanges/task.rb +11 -0
  27. data/lib/legion/transport/message.rb +8 -0
  28. data/lib/legion/transport/messages/base.rb +22 -0
  29. data/lib/legion/transport/messages/lex_register.rb +39 -0
  30. data/lib/legion/transport/messages/node_status.rb +49 -0
  31. data/lib/legion/transport/messages/task_check_subtask.rb +35 -0
  32. data/lib/legion/transport/messages/task_subtask.rb +45 -0
  33. data/lib/legion/transport/messages/task_update.rb +52 -0
  34. data/lib/legion/transport/queue.rb +13 -0
  35. data/lib/legion/transport/queues/bunny.rb +26 -0
  36. data/lib/legion/transport/queues/common.rb +45 -0
  37. data/lib/legion/transport/queues/marchhare.rb +26 -0
  38. data/lib/legion/transport/queues/node_status.rb +21 -0
  39. data/lib/legion/transport/queues/task_log.rb +21 -0
  40. data/lib/legion/transport/queues/task_update.rb +21 -0
  41. data/lib/legion/transport/version.rb +5 -0
  42. data/settings/transport.json +1 -0
  43. metadata +210 -0
@@ -0,0 +1,13 @@
1
+ module Legion
2
+ module Transport
3
+ if RUBY_ENGINE == 'jruby'
4
+ require 'legion/transport/queues/marchhare'
5
+ class Queue < Legion::Transport::Queues::Marchhare
6
+ end
7
+ else
8
+ require 'legion/transport/queues/bunny'
9
+ class Queue < Legion::Transport::Queues::Bunny
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,26 @@
1
+ require 'legion/transport/queues/common'
2
+
3
+ module Legion
4
+ module Transport
5
+ module Queues
6
+ class Bunny < ::Bunny::Queue
7
+ include Legion::Transport::Queues::Common
8
+ def initialize(queue = queue_name, options = {})
9
+ retries ||= 0
10
+ @options = options
11
+ super(channel, queue, options_builder(default_options, queue_options, @options))
12
+ rescue ::Bunny::PreconditionFailed
13
+ retries.zero? ? retries = 1 : raise
14
+ recreate_queue(channel, queue)
15
+ retry
16
+ end
17
+
18
+ def recreate_queue(channel, queue)
19
+ Legion::Logging.warn "Queue:#{queue} exists with wrong parameters, deleting and creating"
20
+ queue = ::Bunny::Queue.new(channel, queue, no_declare: true, passive: true)
21
+ queue.delete(if_empty: true)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,45 @@
1
+ module Legion
2
+ module Transport
3
+ module Queues
4
+ module Common
5
+ include Legion::Transport::Common
6
+ def default_options
7
+ hash = {}
8
+ hash[:manual_ack] = true
9
+ hash[:durable] = true
10
+ hash[:exclusive] = false
11
+ hash[:block] = false
12
+ hash[:arguments] = { 'x-max-priority': 255, 'x-overflow': 'reject-publish' }
13
+ hash
14
+ end
15
+
16
+ def queue_options
17
+ {}
18
+ end
19
+
20
+ def delete(options = { if_unused: true, if_empty: true })
21
+ super(options)
22
+ true
23
+ rescue ::Bunny::PreconditionFailed
24
+ false
25
+ end
26
+
27
+ def channel(options = @options || {})
28
+ @channel if channel_valid?
29
+ @channel = options[:channel] if channel_valid?(options[:channel])
30
+ @channel = open_channel(options) unless channel_valid?(@channel)
31
+ @channel
32
+ end
33
+
34
+ # @queue.channel.acknowledge(delivery_info.delivery_tag)
35
+ def acknowledge(delivery_tag)
36
+ channel.acknowledge(delivery_tag)
37
+ end
38
+
39
+ def reject(delivery_tag, requeue = false)
40
+ channel.reject(delivery_tag, requeue)
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,26 @@
1
+ require 'legion/transport/queues/common'
2
+
3
+ module Legion
4
+ module Transport
5
+ module Queues
6
+ class Marchhare < ::MarchHare::Queue
7
+ include Legion::Transport::Queues::Common
8
+ def initialize(queue = queue_name, options = {})
9
+ retries ||= 0
10
+ @options = options
11
+ super(channel, queue, options_builder(options))
12
+ rescue ::Marchhare::PreconditionFailed
13
+ retries.zero? ? retries = 1 : raise
14
+ recreate_queue(channel, queue)
15
+ retry
16
+ end
17
+
18
+ def recreate_queue(channel, queue)
19
+ Legion::Logging.warn "Queue:#{queue} exists with wrong parameters, deleting and creating"
20
+ queue = ::Marchhare::Queue.new(channel, queue, no_declare: true, passive: true)
21
+ queue.delete(if_empty: true)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,21 @@
1
+ module Legion
2
+ module Transport
3
+ module Queues
4
+ class NodeStatus < Legion::Transport::Queue
5
+ def queue_name
6
+ 'node.status'
7
+ end
8
+
9
+ def queue_options
10
+ hash = {}
11
+ hash[:manual_ack] = true
12
+ hash[:durable] = true
13
+ hash[:exclusive] = false
14
+ hash[:block] = false
15
+ hash[:arguments] = {}
16
+ hash
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ module Legion
2
+ module Transport
3
+ module Queues
4
+ class TaskLog < Legion::Transport::Queue
5
+ def queue_name
6
+ 'task.log'
7
+ end
8
+
9
+ def queue_options
10
+ hash = {}
11
+ hash[:manual_ack] = true
12
+ hash[:durable] = true
13
+ hash[:exclusive] = false
14
+ hash[:block] = false
15
+ hash[:arguments] = { 'x-max-priority': 255 }
16
+ hash
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ module Legion
2
+ module Transport
3
+ module Queues
4
+ class TaskUpdate < Legion::Transport::Queue
5
+ def queue_name
6
+ 'task.update'
7
+ end
8
+
9
+ def queue_options
10
+ hash = {}
11
+ hash[:manual_ack] = true
12
+ hash[:durable] = true
13
+ hash[:exclusive] = false
14
+ hash[:block] = false
15
+ hash[:arguments] = { 'x-max-priority': 252, 'x-dead-letter-exchange': 'task.dlx' }
16
+ hash
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,5 @@
1
+ module Legion
2
+ module Transport
3
+ VERSION = '0.1.0'.freeze
4
+ end
5
+ end
@@ -0,0 +1 @@
1
+ {}
metadata ADDED
@@ -0,0 +1,210 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: legion-transport
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Esity
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-02-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: codecov
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec_junit_formatter
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: legion-settings
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.1'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.1'
111
+ - !ruby/object:Gem::Dependency
112
+ name: bunny
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: legion-logging
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '0.1'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '0.1'
139
+ description: The Legion transport gem
140
+ email:
141
+ - matthewdiverson@gmail.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".circleci/config.yml"
147
+ - ".gitignore"
148
+ - ".rubocop.yml"
149
+ - Gemfile
150
+ - Rakefile
151
+ - bin/console
152
+ - bin/setup
153
+ - bitbucket-pipelines.yml
154
+ - legion-transport.gemspec
155
+ - lib/legion/transport.rb
156
+ - lib/legion/transport/common.rb
157
+ - lib/legion/transport/connection.rb
158
+ - lib/legion/transport/connections/bunny.rb
159
+ - lib/legion/transport/connections/common.rb
160
+ - lib/legion/transport/connections/marchhare.rb
161
+ - lib/legion/transport/consumer.rb
162
+ - lib/legion/transport/consumers/bunny.rb
163
+ - lib/legion/transport/consumers/common.rb
164
+ - lib/legion/transport/consumers/marchhare.rb
165
+ - lib/legion/transport/exchange.rb
166
+ - lib/legion/transport/exchanges/bunny.rb
167
+ - lib/legion/transport/exchanges/common.rb
168
+ - lib/legion/transport/exchanges/lex.rb
169
+ - lib/legion/transport/exchanges/marchhare.rb
170
+ - lib/legion/transport/exchanges/task.rb
171
+ - lib/legion/transport/message.rb
172
+ - lib/legion/transport/messages/base.rb
173
+ - lib/legion/transport/messages/lex_register.rb
174
+ - lib/legion/transport/messages/node_status.rb
175
+ - lib/legion/transport/messages/task_check_subtask.rb
176
+ - lib/legion/transport/messages/task_subtask.rb
177
+ - lib/legion/transport/messages/task_update.rb
178
+ - lib/legion/transport/queue.rb
179
+ - lib/legion/transport/queues/bunny.rb
180
+ - lib/legion/transport/queues/common.rb
181
+ - lib/legion/transport/queues/marchhare.rb
182
+ - lib/legion/transport/queues/node_status.rb
183
+ - lib/legion/transport/queues/task_log.rb
184
+ - lib/legion/transport/queues/task_update.rb
185
+ - lib/legion/transport/version.rb
186
+ - settings/transport.json
187
+ homepage: https://bitbucket.org/legion-io/legion-transport
188
+ licenses: []
189
+ metadata: {}
190
+ post_install_message:
191
+ rdoc_options: []
192
+ require_paths:
193
+ - lib
194
+ required_ruby_version: !ruby/object:Gem::Requirement
195
+ requirements:
196
+ - - ">="
197
+ - !ruby/object:Gem::Version
198
+ version: '0'
199
+ required_rubygems_version: !ruby/object:Gem::Requirement
200
+ requirements:
201
+ - - ">="
202
+ - !ruby/object:Gem::Version
203
+ version: '0'
204
+ requirements: []
205
+ rubyforge_project:
206
+ rubygems_version: 2.7.8
207
+ signing_key:
208
+ specification_version: 4
209
+ summary: Used by Legion to connect with RabbitMQ
210
+ test_files: []