legion-transport 0.1.0 → 1.0.0
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 +4 -4
- data/.circleci/config.yml +12 -12
- data/.idea/.rakeTasks +7 -0
- data/.idea/legion-transport.iml +45 -0
- data/.idea/misc.xml +7 -0
- data/.idea/modules.xml +8 -0
- data/.idea/vagrant.xml +7 -0
- data/.idea/workspace.xml +14 -0
- data/.rspec +1 -0
- data/.rubocop.yml +1 -8
- data/CHANGELOG.md +0 -0
- data/Gemfile +0 -1
- data/README.md +35 -0
- data/legion-transport.gemspec +15 -5
- data/lib/legion/transport.rb +11 -9
- data/lib/legion/transport/common.rb +23 -18
- data/lib/legion/transport/connection.rb +55 -12
- data/lib/legion/transport/consumer.rb +7 -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 +94 -2
- data/lib/legion/transport/messages/check_subtask.rb +25 -0
- data/lib/legion/transport/messages/dynamic.rb +24 -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 +32 -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 -23
- data/lib/legion/transport/queue.rb +63 -6
- data/lib/legion/transport/queues/node.rb +15 -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 +64 -0
- data/lib/legion/transport/version.rb +1 -1
- data/settings/transport.json +9 -1
- metadata +81 -33
- 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
@@ -1,36 +0,0 @@
|
|
1
|
-
module Legion
|
2
|
-
module Transport
|
3
|
-
module Connections
|
4
|
-
module Common
|
5
|
-
def options_builder(options = {})
|
6
|
-
settings = Legion::Settings[:transport][:rabbitmq] if Legion::Settings[:transport].is_a? Hash
|
7
|
-
hash = default_options.merge(settings) unless settings.nil?
|
8
|
-
hash = {} if settings.nil?
|
9
|
-
hash = hash.merge(options) if options.is_a? Hash
|
10
|
-
hash
|
11
|
-
end
|
12
|
-
|
13
|
-
def url_builder(options = default_options)
|
14
|
-
"amqp://#{options[:user]}:#{options[:password]}@#{options[:host]}:#{options[:port]}"
|
15
|
-
end
|
16
|
-
|
17
|
-
def default_options
|
18
|
-
default = {}
|
19
|
-
default[:read_timeout] = 30
|
20
|
-
default[:heartbeat] = 1
|
21
|
-
default[:automatically_recover] = true
|
22
|
-
default[:continuation_timeout] = 4000
|
23
|
-
default[:network_recovery_interval] = 5
|
24
|
-
default[:host] = '127.0.0.1'
|
25
|
-
default[:port] = '5672'
|
26
|
-
default[:user] = 'guest'
|
27
|
-
default[:password] = 'guest'
|
28
|
-
default[:vhost] = '/'
|
29
|
-
default[:log_level] = :info
|
30
|
-
|
31
|
-
default
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'legion/transport/connections/common'
|
2
|
-
|
3
|
-
module Legion
|
4
|
-
module Transport
|
5
|
-
module Connections
|
6
|
-
module Marchhare
|
7
|
-
include Legion::Transport::Connections::Common
|
8
|
-
attr_accessor :session, :channel
|
9
|
-
|
10
|
-
def initialize(options = {})
|
11
|
-
options = options_builder(options)
|
12
|
-
@session = MarchHare.connect(options)
|
13
|
-
@session.start
|
14
|
-
@channel = @session.create_channel
|
15
|
-
Legion::Settings[:transport][:rabbitmq][:connected] = true
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
module Legion
|
2
|
-
module Transport
|
3
|
-
module Consumer
|
4
|
-
class Bunny < ::Bunny::Consumer
|
5
|
-
def initialize(queue, no_ack = false, exclusive = false, arguments = {})
|
6
|
-
super(Legion::Transport::Connections.new.channel, queue, '', no_ack, exclusive, arguments)
|
7
|
-
end
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
module Legion
|
2
|
-
module Transport
|
3
|
-
module Consumer
|
4
|
-
class Marchhare < ::MarchHare::Consumer
|
5
|
-
def initialize(queue, no_ack = false, exclusive = false, arguments = {})
|
6
|
-
super(Legion::Transport::Connection::Marchhare.new.channel, queue, '', no_ack, exclusive, arguments)
|
7
|
-
end
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'legion/transport/exchanges/common.rb'
|
2
|
-
|
3
|
-
module Legion
|
4
|
-
module Transport
|
5
|
-
module Exchanges
|
6
|
-
class Bunny < ::Bunny::Exchange
|
7
|
-
include Legion::Transport::Exchanges::Common
|
8
|
-
def initialize(exchange = exchange_name, options = {})
|
9
|
-
retries ||= 0
|
10
|
-
@options = options
|
11
|
-
@type = options[:type] || default_type
|
12
|
-
|
13
|
-
super(channel, @type, exchange, options_builder(default_options, exchange_options, @options))
|
14
|
-
rescue ::Bunny::PreconditionFailed
|
15
|
-
retries.zero? ? retries = 1 : raise
|
16
|
-
recreate_exchange(channel, @type, exchange)
|
17
|
-
retry
|
18
|
-
end
|
19
|
-
|
20
|
-
def recreate_exchange(channel, type, exchange)
|
21
|
-
Legion::Logging.warn "Exchange:#{exchange} exists with wrong parameters, deleting and creating"
|
22
|
-
exchange = ::Bunny::Exchange.new(channel, type, exchange, no_declare: true)
|
23
|
-
exchange.delete
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module Legion
|
2
|
-
module Transport
|
3
|
-
module Exchanges
|
4
|
-
module Common
|
5
|
-
include Legion::Transport::Common
|
6
|
-
|
7
|
-
def default_options
|
8
|
-
hash = {}
|
9
|
-
hash[:durable] = true
|
10
|
-
hash[:auto_delete] = false
|
11
|
-
hash[:arguments] = {}
|
12
|
-
hash
|
13
|
-
end
|
14
|
-
|
15
|
-
def exchange_options
|
16
|
-
{}
|
17
|
-
end
|
18
|
-
|
19
|
-
def delete(options = {})
|
20
|
-
super(options)
|
21
|
-
true
|
22
|
-
rescue ::Bunny::PreconditionFailed
|
23
|
-
false
|
24
|
-
end
|
25
|
-
|
26
|
-
def default_type
|
27
|
-
'topic'
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module Legion
|
2
|
-
module Transport
|
3
|
-
module Exchanges
|
4
|
-
class Marchhare < ::MarchHare::Exchange
|
5
|
-
attr_accessor :channel
|
6
|
-
def self.create(exchange, _type = :direct, _opts = {})
|
7
|
-
@channel = Legion::Transport::Connections::Marchhare.new
|
8
|
-
new(@channel.channel, exchange, type: :direct, durable: true)
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.close
|
12
|
-
@channel.close
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
module Legion
|
2
|
-
module Transport
|
3
|
-
module Messages
|
4
|
-
module Base
|
5
|
-
include Legion::Transport::Common
|
6
|
-
def publish(_options = {}) # rubocop:disable Metrics/AbcSize
|
7
|
-
validate if @valid.nil?
|
8
|
-
raise unless @valid
|
9
|
-
|
10
|
-
thing = exchange.new
|
11
|
-
thing.publish(message) if routing_key.nil?
|
12
|
-
thing.publish(message, routing_key: routing_key) unless routing_key.nil?
|
13
|
-
thing.close
|
14
|
-
end
|
15
|
-
|
16
|
-
def validate
|
17
|
-
@valid = true
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'legion/transport/exchanges/task_update'
|
2
|
-
|
3
|
-
module Legion
|
4
|
-
module Exception
|
5
|
-
class InvalidTaskStatus; end
|
6
|
-
class InvalidTaskId; end
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
module Legion
|
11
|
-
module Transport
|
12
|
-
module Messages
|
13
|
-
# Used for sending a task update, to be moved
|
14
|
-
class TaskUpdate < Legion::Transport::Message
|
15
|
-
attr_accessor :status
|
16
|
-
attr_reader :task_id, :valid
|
17
|
-
def initialize(task_id, status = 'unknown', options = {})
|
18
|
-
@status = status
|
19
|
-
@task_id = task_id
|
20
|
-
@routing_key = options[:routing_key] unless options[:routing_key].nil?
|
21
|
-
@valid = validate
|
22
|
-
end
|
23
|
-
|
24
|
-
def exchange
|
25
|
-
Legion::Transport::Exchanges::Task
|
26
|
-
end
|
27
|
-
|
28
|
-
def message(status = @status, task_id = @task_id)
|
29
|
-
Legion::JSON.dump(status: status, task_id: task_id)
|
30
|
-
end
|
31
|
-
|
32
|
-
def validate(status = @status, task_id = @task_id)
|
33
|
-
raise Legion::Exception::InvalidTaskId unless task_id.is_a? Integer
|
34
|
-
raise Legion::Exception::InvalidTaskStatus unless valid_status.include? status
|
35
|
-
|
36
|
-
@valid = true
|
37
|
-
end
|
38
|
-
|
39
|
-
def valid_status
|
40
|
-
conditioner = ['conditioner.queued', 'conditioner.failed', 'conditioner.exception']
|
41
|
-
transfomer = ['transformer.queued', 'transformer.succeeded', 'transformer.exception']
|
42
|
-
task = ['task.scheduled', 'task.queued', 'task.completed']
|
43
|
-
status = conditioner + transfomer + task
|
44
|
-
status
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
require 'legion/transport/exchanges/task'
|
2
|
-
|
3
|
-
module Legion
|
4
|
-
module Transport
|
5
|
-
module Messages
|
6
|
-
class TaskCheckSubtask < Legion::Transport::Message
|
7
|
-
attr_accessor :status
|
8
|
-
attr_reader :task_id, :valid
|
9
|
-
def initialize(namespace, method, result, _options = {})
|
10
|
-
@namespace = namespace
|
11
|
-
@method = method
|
12
|
-
@result = result
|
13
|
-
@routing_key = 'task.subtask.check'
|
14
|
-
validate
|
15
|
-
end
|
16
|
-
|
17
|
-
def exchange
|
18
|
-
Legion::Transport::Exchanges::Task
|
19
|
-
end
|
20
|
-
|
21
|
-
def message(namespace = @namespace, method = @method, result = @result)
|
22
|
-
Legion::JSON.dump(args: { namespace: namespace, method: method, result: result })
|
23
|
-
end
|
24
|
-
|
25
|
-
def routing_key
|
26
|
-
'task.subtask.check'
|
27
|
-
end
|
28
|
-
|
29
|
-
def validate(_namespace = @namespace, _method = @method, _result = @result, _options = {})
|
30
|
-
@valid = true
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
require 'legion/transport/exchanges/task'
|
2
|
-
|
3
|
-
module Legion
|
4
|
-
module Transport
|
5
|
-
module Messages
|
6
|
-
class TaskSubTask < Legion::Transport::Message
|
7
|
-
attr_accessor :status
|
8
|
-
attr_reader :task_id, :valid
|
9
|
-
def initialize(relationship_id, trigger_id, conditions, transformations, task_id = nil, options = {}) # rubocop:disable Metrics/ParameterLists,Metrics/LineLength
|
10
|
-
@relationship_id = relationship_id
|
11
|
-
@trigger_id = trigger_id
|
12
|
-
@conditions = conditions
|
13
|
-
@tranformations = transformations
|
14
|
-
@task_id = task_id
|
15
|
-
@options = options
|
16
|
-
@routing_key = 'task.subtask'
|
17
|
-
validate
|
18
|
-
end
|
19
|
-
|
20
|
-
def exchange
|
21
|
-
Legion::Transport::Exchanges::Task
|
22
|
-
end
|
23
|
-
|
24
|
-
def message(relationship_id = @relationship_id, trigger_id = @trigger_id, conditions = @conditions, transformations = @tranformations, task_id = @task_id, options = @options) # rubocop:disable Metrics/ParameterLists,Metrics/LineLength
|
25
|
-
Legion::JSON.dump(args: {
|
26
|
-
relationship_id: relationship_id,
|
27
|
-
trigger_id: trigger_id,
|
28
|
-
conditions: conditions,
|
29
|
-
task_id: task_id,
|
30
|
-
transformations: transformations,
|
31
|
-
options: options
|
32
|
-
})
|
33
|
-
end
|
34
|
-
|
35
|
-
def routing_key
|
36
|
-
'task.subtask'
|
37
|
-
end
|
38
|
-
|
39
|
-
def validate(_namespace = @namespace, _method = @method, _result = @result, _options = {})
|
40
|
-
@valid = true
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
@@ -1,26 +0,0 @@
|
|
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
|
@@ -1,45 +0,0 @@
|
|
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
|
@@ -1,26 +0,0 @@
|
|
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
|