legion-transport 0.1.0 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +53 -80
- data/.rspec +1 -0
- data/.rubocop.yml +3 -9
- data/CHANGELOG.md +9 -0
- data/Gemfile +0 -1
- data/README.md +3 -0
- data/bitbucket-pipelines.yml +1 -1
- data/legion-transport.gemspec +19 -14
- data/lib/legion/transport.rb +12 -10
- data/lib/legion/transport/common.rb +23 -18
- data/lib/legion/transport/connection.rb +56 -12
- data/lib/legion/transport/consumer.rb +8 -1
- data/lib/legion/transport/exchange.rb +44 -6
- data/lib/legion/transport/exchanges/crypt.rb +11 -0
- data/lib/legion/transport/exchanges/node.rb +11 -0
- data/lib/legion/transport/message.rb +100 -2
- data/lib/legion/transport/messages/check_subtask.rb +25 -0
- data/lib/legion/transport/messages/dynamic.rb +25 -0
- data/lib/legion/transport/messages/lex_register.rb +11 -19
- data/lib/legion/transport/messages/node_health.rb +21 -0
- data/lib/legion/transport/messages/request_cluster_secret.rb +33 -0
- data/lib/legion/transport/messages/subtask.rb +38 -0
- data/lib/legion/transport/messages/task_log.rb +36 -0
- data/lib/legion/transport/messages/task_update.rb +3 -24
- data/lib/legion/transport/queue.rb +65 -6
- data/lib/legion/transport/queues/node.rb +15 -0
- data/lib/legion/transport/queues/node_crypt.rb +21 -0
- data/lib/legion/transport/queues/node_status.rb +1 -1
- data/lib/legion/transport/queues/task_log.rb +1 -1
- data/lib/legion/transport/queues/task_update.rb +1 -1
- data/lib/legion/transport/settings.rb +72 -0
- data/lib/legion/transport/version.rb +1 -1
- data/settings/transport.json +5 -1
- data/sonar-project.properties +12 -0
- metadata +93 -49
- data/lib/legion/transport/connections/bunny.rb +0 -53
- data/lib/legion/transport/connections/common.rb +0 -36
- data/lib/legion/transport/connections/marchhare.rb +0 -20
- data/lib/legion/transport/consumers/bunny.rb +0 -11
- data/lib/legion/transport/consumers/common.rb +0 -8
- data/lib/legion/transport/consumers/marchhare.rb +0 -11
- data/lib/legion/transport/exchanges/bunny.rb +0 -28
- data/lib/legion/transport/exchanges/common.rb +0 -32
- data/lib/legion/transport/exchanges/marchhare.rb +0 -17
- data/lib/legion/transport/messages/base.rb +0 -22
- data/lib/legion/transport/messages/node_status.rb +0 -49
- data/lib/legion/transport/messages/task_check_subtask.rb +0 -35
- data/lib/legion/transport/messages/task_subtask.rb +0 -45
- data/lib/legion/transport/queues/bunny.rb +0 -26
- data/lib/legion/transport/queues/common.rb +0 -45
- data/lib/legion/transport/queues/marchhare.rb +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aca9d21a2d161f0838dc16ce328d81c3ba42360a777c63e6aa805f6c52502e13
|
4
|
+
data.tar.gz: 46af9353894537c81d73a68e01522498181d6d2fb54ae3fcdec465ebb75f8675
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: add6818532d2159f4fa2be2a40148694f24511f7ca5095ad4477c9e0b72d70c546b2c7ba7ce6b60b44fa9b538c64e08d032dede1f341bbcb6e1831f541828d0e
|
7
|
+
data.tar.gz: 754b708ce889ff36ab763f4f72887895195721a9f5e43bea168e802ad6cde0e3fc813ef9ed7ac2e11d677388777d264fc635b57912376f96dff1b03d71108ce3
|
data/.circleci/config.yml
CHANGED
@@ -1,116 +1,89 @@
|
|
1
|
-
version: 2
|
1
|
+
version: 2.1
|
2
|
+
orbs:
|
3
|
+
ruby: circleci/ruby@0.2.1
|
4
|
+
sonarcloud: sonarsource/sonarcloud@1.0.1
|
5
|
+
|
2
6
|
jobs:
|
3
7
|
"rubocop":
|
4
8
|
docker:
|
5
|
-
- image: circleci/ruby:2.
|
9
|
+
- image: circleci/ruby:2.7-node
|
6
10
|
steps:
|
7
11
|
- checkout
|
8
|
-
-
|
12
|
+
- ruby/load-cache
|
13
|
+
- ruby/install-deps
|
9
14
|
- run:
|
10
15
|
name: Run Rubocop
|
11
|
-
command: rubocop
|
12
|
-
-
|
13
|
-
|
14
|
-
"ruby-2.3":
|
16
|
+
command: bundle exec rubocop
|
17
|
+
- ruby/save-cache
|
18
|
+
"ruby-two-five":
|
15
19
|
docker:
|
16
|
-
- image: circleci/ruby:2.
|
20
|
+
- image: circleci/ruby:2.5
|
17
21
|
- image: rabbitmq:3.7
|
18
22
|
steps:
|
19
23
|
- checkout
|
24
|
+
- ruby/load-cache
|
20
25
|
- run:
|
21
|
-
name:
|
22
|
-
command:
|
23
|
-
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
- store_test_results:
|
28
|
-
path: test-results
|
29
|
-
|
30
|
-
"ruby-2.4":
|
26
|
+
name: update bundler
|
27
|
+
command: gem update bundler
|
28
|
+
- ruby/install-deps
|
29
|
+
- ruby/run-tests
|
30
|
+
- ruby/save-cache
|
31
|
+
"ruby-two-six":
|
31
32
|
docker:
|
32
|
-
- image: circleci/ruby:2.
|
33
|
+
- image: circleci/ruby:2.6
|
33
34
|
- image: rabbitmq:3.7
|
34
35
|
steps:
|
35
36
|
- checkout
|
37
|
+
- ruby/load-cache
|
36
38
|
- run:
|
37
|
-
name:
|
38
|
-
command:
|
39
|
-
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
- store_test_results:
|
44
|
-
path: test-results
|
45
|
-
"ruby-2.5":
|
39
|
+
name: update bundler
|
40
|
+
command: gem update bundler
|
41
|
+
- ruby/install-deps
|
42
|
+
- ruby/run-tests
|
43
|
+
- ruby/save-cache
|
44
|
+
"ruby-two-seven":
|
46
45
|
docker:
|
47
|
-
- image: circleci/ruby:2.
|
46
|
+
- image: circleci/ruby:2.7
|
48
47
|
- image: rabbitmq:3.7
|
49
48
|
steps:
|
50
49
|
- checkout
|
50
|
+
- ruby/load-cache
|
51
51
|
- run:
|
52
|
-
name:
|
53
|
-
command:
|
54
|
-
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
- store_test_results:
|
59
|
-
path: test-results
|
60
|
-
"ruby-2.6":
|
52
|
+
name: update bundler
|
53
|
+
command: gem update bundler
|
54
|
+
- ruby/install-deps
|
55
|
+
- ruby/run-tests
|
56
|
+
- ruby/save-cache
|
57
|
+
"sonarcloud":
|
61
58
|
docker:
|
62
|
-
- image: circleci/ruby:2.
|
59
|
+
- image: circleci/ruby:2.7
|
63
60
|
- image: rabbitmq:3.7
|
64
61
|
steps:
|
65
62
|
- checkout
|
63
|
+
- ruby/load-cache
|
64
|
+
- ruby/install-deps
|
65
|
+
- ruby/run-tests
|
66
66
|
- run:
|
67
|
-
name:
|
68
|
-
command: bundle
|
69
|
-
-
|
70
|
-
|
71
|
-
command: bundle exec rspec --format progress --format RspecJunitFormatter -o test-results/rspec/results.xml
|
72
|
-
when: always
|
73
|
-
- store_test_results:
|
74
|
-
path: test-results
|
75
|
-
"jruby-9.2":
|
76
|
-
docker:
|
77
|
-
- image: circleci/jruby:9.2
|
78
|
-
- image: rabbitmq:3.7
|
79
|
-
steps:
|
80
|
-
- checkout
|
81
|
-
- run:
|
82
|
-
name: Bundle Install
|
83
|
-
command: bundle install
|
84
|
-
- run:
|
85
|
-
name: Run RSpec
|
86
|
-
command: bundle exec rspec --format progress --format RspecJunitFormatter -o test-results/rspec/results.xml
|
87
|
-
when: always
|
88
|
-
- store_test_results:
|
89
|
-
path: test-results
|
67
|
+
name: Run Rubocop
|
68
|
+
command: bundle exec rubocop --format=json --out=rubocop-result.json
|
69
|
+
- sonarcloud/scan
|
70
|
+
- ruby/save-cache
|
90
71
|
|
91
72
|
workflows:
|
92
73
|
version: 2
|
93
|
-
|
74
|
+
rubocop-rspec:
|
94
75
|
jobs:
|
95
76
|
- rubocop
|
96
|
-
- ruby-
|
97
|
-
requires:
|
98
|
-
- ruby-2.4
|
99
|
-
filters:
|
100
|
-
branches:
|
101
|
-
only: /\bdevelop\b|\bmaster\b/
|
102
|
-
- ruby-2.4:
|
77
|
+
- ruby-two-five:
|
103
78
|
requires:
|
104
79
|
- rubocop
|
105
|
-
- ruby-
|
80
|
+
- ruby-two-six:
|
81
|
+
requires:
|
82
|
+
- ruby-two-five
|
83
|
+
- ruby-two-seven:
|
106
84
|
requires:
|
107
|
-
- ruby-
|
108
|
-
|
109
|
-
branches:
|
110
|
-
only: /\bdevelop\b|\bmaster\b/
|
111
|
-
- ruby-2.6:
|
85
|
+
- ruby-two-five
|
86
|
+
- sonarcloud:
|
112
87
|
requires:
|
113
|
-
- ruby-
|
114
|
-
|
115
|
-
branches:
|
116
|
-
only: /\bdevelop\b|\bmaster\b/
|
88
|
+
- ruby-two-seven
|
89
|
+
- ruby-two-six
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.rubocop.yml
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
Layout/LineLength:
|
2
2
|
Max: 120
|
3
3
|
Metrics/MethodLength:
|
4
4
|
Max: 30
|
@@ -6,21 +6,15 @@ Metrics/ClassLength:
|
|
6
6
|
Max: 1500
|
7
7
|
Metrics/BlockLength:
|
8
8
|
Max: 50
|
9
|
-
Exclude:
|
10
|
-
- 'spec/legion/connections/*'
|
11
9
|
Layout/SpaceAroundEqualsInParameterDefault:
|
12
10
|
EnforcedStyle: space
|
13
11
|
Style/SymbolArray:
|
14
12
|
Enabled: true
|
15
|
-
Layout/AlignHash:
|
16
|
-
EnforcedHashRocketStyle: table
|
17
|
-
EnforcedColonStyle: table
|
18
|
-
Style/HashSyntax:
|
19
|
-
EnforcedStyle: ruby19_no_mixed_keys
|
20
13
|
Style/Documentation:
|
21
14
|
Enabled: false
|
22
15
|
AllCops:
|
23
|
-
TargetRubyVersion: 2.
|
16
|
+
TargetRubyVersion: 2.5
|
17
|
+
NewCops: enable
|
24
18
|
Style/FrozenStringLiteralComment:
|
25
19
|
Enabled: false
|
26
20
|
Naming/FileName:
|
data/CHANGELOG.md
ADDED
data/Gemfile
CHANGED
data/README.md
ADDED
data/bitbucket-pipelines.yml
CHANGED
data/legion-transport.gemspec
CHANGED
@@ -11,28 +11,33 @@ Gem::Specification.new do |spec|
|
|
11
11
|
spec.summary = 'Used by Legion to connect with RabbitMQ'
|
12
12
|
spec.description = 'The Legion transport gem'
|
13
13
|
spec.homepage = 'https://bitbucket.org/legion-io/legion-transport'
|
14
|
+
spec.required_ruby_version = '>= 2.5.0'
|
14
15
|
|
15
|
-
spec.
|
16
|
+
spec.metadata = {
|
17
|
+
'bug_tracker_uri' => 'https://legionio.atlassian.net/projects/TRANSPORT/issues',
|
18
|
+
'changelog_uri' => 'https://bitbucket.org/legion-io/legion-transport/src/master/CHANGELOG.md',
|
19
|
+
'homepage_uri' => 'https://bitbucket.org/legion-io/legion-transport',
|
20
|
+
'wiki_uri' => 'https://bitbucket.org/legion-io/legion-transport/wiki/Home'
|
21
|
+
}
|
22
|
+
|
23
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
16
24
|
f.match(%r{^(test|spec|features)/})
|
17
25
|
end
|
18
|
-
spec.bindir = 'exe'
|
19
26
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
27
|
spec.require_paths = ['lib']
|
21
28
|
|
22
|
-
spec.add_development_dependency 'bundler'
|
29
|
+
spec.add_development_dependency 'bundler'
|
23
30
|
spec.add_development_dependency 'codecov'
|
24
|
-
spec.add_development_dependency '
|
25
|
-
spec.add_development_dependency '
|
31
|
+
spec.add_development_dependency 'legion-logging'
|
32
|
+
spec.add_development_dependency 'legion-settings'
|
33
|
+
spec.add_development_dependency 'march_hare' if RUBY_ENGINE == 'jruby'
|
34
|
+
spec.add_development_dependency 'rake'
|
35
|
+
spec.add_development_dependency 'rspec'
|
26
36
|
spec.add_development_dependency 'rspec_junit_formatter'
|
27
37
|
spec.add_development_dependency 'rubocop'
|
38
|
+
spec.add_development_dependency 'simplecov'
|
28
39
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
else
|
33
|
-
spec.add_development_dependency 'legion-settings', '~> 0.1'
|
34
|
-
spec.add_dependency 'bunny'
|
35
|
-
end
|
36
|
-
|
37
|
-
spec.add_development_dependency 'legion-logging', '~> 0.1'
|
40
|
+
spec.add_dependency 'bunny'
|
41
|
+
spec.add_dependency 'concurrent-ruby'
|
42
|
+
spec.add_dependency 'legion-json'
|
38
43
|
end
|
data/lib/legion/transport.rb
CHANGED
@@ -1,20 +1,22 @@
|
|
1
|
-
|
1
|
+
require_relative 'transport/version'
|
2
|
+
require_relative 'transport/settings'
|
2
3
|
|
3
4
|
module Legion
|
4
|
-
# Base Legion::Transport
|
5
5
|
module Transport
|
6
|
-
if RUBY_ENGINE == 'jruby'
|
6
|
+
if RUBY_ENGINE == 'jruby' && defined?(::Marchhare)
|
7
7
|
require 'marchhare'
|
8
|
-
|
8
|
+
TYPE = 'marchhare'.freeze
|
9
|
+
CONNECTOR = ::Marchhare
|
9
10
|
else
|
10
11
|
require 'bunny'
|
11
|
-
|
12
|
+
TYPE = 'bunny'.freeze
|
13
|
+
CONNECTOR = ::Bunny
|
12
14
|
end
|
13
15
|
end
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
require_relative 'transport/common'
|
18
|
+
require_relative 'transport/queue'
|
19
|
+
require_relative 'transport/exchange'
|
20
|
+
require_relative 'transport/consumer'
|
21
|
+
require_relative 'transport/message'
|
20
22
|
end
|
@@ -3,16 +3,12 @@ require 'legion/transport/connection'
|
|
3
3
|
module Legion
|
4
4
|
module Transport
|
5
5
|
module Common
|
6
|
-
def open_channel(
|
7
|
-
@channel = Legion::Transport::Connection.
|
6
|
+
def open_channel(_options = {})
|
7
|
+
@channel = Legion::Transport::Connection.channel
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
11
|
-
|
12
|
-
return false unless channel.instance_of?(::Bunny::Channel)
|
13
|
-
return false if channel.closed?
|
14
|
-
|
15
|
-
true
|
10
|
+
def channel_open?
|
11
|
+
channel.open?
|
16
12
|
end
|
17
13
|
|
18
14
|
def options_builder(first, *args)
|
@@ -51,20 +47,29 @@ module Legion
|
|
51
47
|
end
|
52
48
|
# rubocop:enable all
|
53
49
|
|
54
|
-
def
|
55
|
-
@channel.
|
50
|
+
def channel
|
51
|
+
@channel ||= Legion::Transport::Connection.channel
|
52
|
+
end
|
53
|
+
|
54
|
+
def close!
|
55
|
+
Legion::Logging.error 'close! called'
|
56
|
+
false unless Legion::Transport::Connection.channel_open?
|
57
|
+
Legion::Transport::Connection.channel.close
|
56
58
|
end
|
57
59
|
|
58
|
-
def
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
@channel
|
60
|
+
def close
|
61
|
+
Legion::Logging.error 'close called'
|
62
|
+
Legion::Logging.warn 'close called, but method is called close!'
|
63
|
+
close!
|
63
64
|
end
|
64
65
|
|
65
|
-
def
|
66
|
-
|
67
|
-
|
66
|
+
def generate_consumer_tag(lex_name: nil, runner_name: nil, thread: Thread.current.object_id)
|
67
|
+
tag = "#{Legion::Settings[:client][:name]}_"
|
68
|
+
tag.concat("#{lex_name}_") unless lex_name.nil?
|
69
|
+
tag.concat("#{runner_name}_") unless runner_name.nil?
|
70
|
+
tag.concat("#{thread}_")
|
71
|
+
tag.concat(SecureRandom.hex)
|
72
|
+
tag
|
68
73
|
end
|
69
74
|
end
|
70
75
|
end
|
@@ -1,17 +1,61 @@
|
|
1
|
+
require 'concurrent-ruby'
|
2
|
+
|
1
3
|
module Legion
|
2
4
|
module Transport
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
5
|
+
module Connection
|
6
|
+
class << self
|
7
|
+
def connector
|
8
|
+
Legion::Transport::CONNECTOR
|
9
|
+
end
|
10
|
+
|
11
|
+
def setup # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
|
12
|
+
if @session.respond_to?(:value) && session.respond_to?(:closed?) && session.closed?
|
13
|
+
@channel_thread = Concurrent::ThreadLocalVar.new
|
14
|
+
elsif @session.respond_to?(:value) && session.respond_to?(:closed?) && session.open?
|
15
|
+
return nil
|
16
|
+
else
|
17
|
+
@session ||= Concurrent::Atom.new(
|
18
|
+
connector.new(
|
19
|
+
Legion::Settings[:transport][:connection],
|
20
|
+
logger: Legion::Logging::Logger.new(level: 'warn'),
|
21
|
+
log_level: :info
|
22
|
+
)
|
23
|
+
)
|
24
|
+
@channel_thread = Concurrent::ThreadLocalVar.new
|
25
|
+
end
|
26
|
+
|
27
|
+
session.start
|
28
|
+
session.create_channel.basic_qos(1, true)
|
29
|
+
end
|
30
|
+
|
31
|
+
def channel
|
32
|
+
return @channel_thread.value if !@channel_thread.value.nil? && @channel_thread.value.open?
|
33
|
+
|
34
|
+
@channel_thread.value = session.create_channel
|
35
|
+
@channel_thread.value.prefetch(Legion::Settings[:transport][:prefetch])
|
36
|
+
@channel_thread.value
|
37
|
+
end
|
38
|
+
|
39
|
+
def session
|
40
|
+
nil if @session.nil?
|
41
|
+
@session.value
|
42
|
+
end
|
43
|
+
|
44
|
+
def channel_thread
|
45
|
+
channel
|
46
|
+
end
|
47
|
+
|
48
|
+
def channel_open?
|
49
|
+
channel.open?
|
50
|
+
end
|
51
|
+
|
52
|
+
def session_open?
|
53
|
+
session.open?
|
54
|
+
end
|
55
|
+
|
56
|
+
def shutdown
|
57
|
+
session.close
|
58
|
+
end
|
15
59
|
end
|
16
60
|
end
|
17
61
|
end
|