legionio 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.circleci/config.yml +98 -0
- data/.rspec +2 -0
- data/.rubocop.yml +38 -8
- data/CHANGELOG.md +7 -0
- data/Gemfile +12 -9
- data/LICENSE.txt +21 -0
- data/README.md +46 -0
- data/Rakefile +1 -1
- data/bin/console +3 -2
- data/bin/legion +9 -6
- data/bin/test +28 -1
- data/bitbucket-pipelines.yml +13 -8
- data/legion.gemspec +27 -21
- data/lib/legion.rb +14 -5
- data/lib/legion/exceptions/handled_task.rb +6 -0
- data/lib/legion/exceptions/missingargument.rb +2 -2
- data/lib/legion/extensions.rb +151 -0
- data/lib/legion/extensions/actors/base.rb +53 -0
- data/lib/legion/extensions/actors/every.rb +50 -0
- data/lib/legion/extensions/actors/loop.rb +34 -0
- data/lib/legion/extensions/actors/nothing.rb +15 -0
- data/lib/legion/extensions/actors/once.rb +42 -0
- data/lib/legion/extensions/actors/poll.rb +90 -0
- data/lib/legion/extensions/actors/subscription.rb +120 -0
- data/lib/legion/extensions/builders/actors.rb +62 -0
- data/lib/legion/extensions/builders/base.rb +38 -0
- data/lib/legion/extensions/builders/helpers.rb +26 -0
- data/lib/legion/extensions/builders/runners.rb +54 -0
- data/lib/legion/extensions/core.rb +84 -0
- data/lib/legion/extensions/helpers/base.rb +88 -0
- data/lib/legion/extensions/helpers/core.rb +20 -0
- data/lib/legion/extensions/helpers/lex.rb +22 -0
- data/lib/legion/extensions/helpers/logger.rb +48 -0
- data/lib/legion/extensions/helpers/task.rb +42 -0
- data/lib/legion/extensions/helpers/transport.rb +45 -0
- data/lib/legion/extensions/transport.rb +156 -0
- data/lib/legion/process.rb +8 -3
- data/lib/legion/runner.rb +57 -0
- data/lib/legion/runner/log.rb +12 -0
- data/lib/legion/runner/status.rb +72 -0
- data/lib/legion/service.rb +44 -27
- data/lib/legion/supervison.rb +10 -24
- data/lib/legion/version.rb +1 -1
- metadata +184 -46
- data/lib/legion/extension/loader.rb +0 -96
- data/lib/legion/runners/runner.rb +0 -58
@@ -1,96 +0,0 @@
|
|
1
|
-
require 'legion/transport/messages/lex_register'
|
2
|
-
|
3
|
-
module Legion
|
4
|
-
module Extension
|
5
|
-
# New magical extension loader
|
6
|
-
class Loader
|
7
|
-
attr_reader :loaded_extensions
|
8
|
-
def initialize(supervision, _extensions = Legion::Settings[:legion][:extensions])
|
9
|
-
@loaded_extensions = []
|
10
|
-
@supervision = supervision
|
11
|
-
end
|
12
|
-
|
13
|
-
def load_extensions(extensions = Legion::Settings[:legion][:extensions])
|
14
|
-
extensions.each do |extension, values|
|
15
|
-
Legion::Logging.debug "Skipping #{extension} because it's disabled" unless values[:enabled]
|
16
|
-
next unless values[:enabled]
|
17
|
-
|
18
|
-
result = load_extension(extension, values)
|
19
|
-
Legion::Logging.info("#{extension} was loaded") if result
|
20
|
-
Legion::Logging.warn("#{extension} failed to load") unless result
|
21
|
-
@loaded_extensions.push(extension) if result
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def load_actor_pool(klass, name, size = 1)
|
26
|
-
@supervision.supervision_group.pool(klass, as: name, size: size)
|
27
|
-
end
|
28
|
-
|
29
|
-
def register_lex(_extension, lex_methods)
|
30
|
-
lex_methods.each do |namespace|
|
31
|
-
namespace[:class_methods].each do |class_method, _attrs|
|
32
|
-
options = { namespace: {}, method: {} }
|
33
|
-
options[:namespace][:queue] = namespace[:queue] unless namespace[:queue].nil?
|
34
|
-
options[:namespace][:uri] = namespace[:uri] unless namespace[:uri].nil?
|
35
|
-
Legion::Transport::Messages::LexRegister.new(namespace[:namespace], class_method, options).publish
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def load_extension(extension, values) # rubocop:disable Metrics/AbcSize
|
41
|
-
Legion::Logging.debug "Skipping #{extension} because it's disabled" unless values[:enabled]
|
42
|
-
return false unless values[:enabled]
|
43
|
-
|
44
|
-
unless gem_load(extension)
|
45
|
-
Legion::Logging.warn "#{extension} failed to load gem path"
|
46
|
-
return false
|
47
|
-
end
|
48
|
-
|
49
|
-
klass = Kernel.const_get(values[:class])
|
50
|
-
klass.autobuild
|
51
|
-
|
52
|
-
register_lex(extension, klass.lex_methods)
|
53
|
-
|
54
|
-
klass.actors.each do |actor|
|
55
|
-
load_actor_pool(actor[:class], actor[:group_name], 1)
|
56
|
-
end
|
57
|
-
true
|
58
|
-
rescue Sequel::DatabaseConnectionError => exception
|
59
|
-
Legion::Logging.fatal("Legion::Extension #{extension} requires a database connection but failed")
|
60
|
-
Legion::Logging.debug("Extension failed with #{exception.message}")
|
61
|
-
Legion::Logging.debug("Backtrace: #{exception.backtrace}")
|
62
|
-
false
|
63
|
-
rescue NameError => exception
|
64
|
-
Legion::Logging.fatal("Legion::Extension #{extension} failed to load, moving on without it")
|
65
|
-
Legion::Logging.warn("Extension failed with #{exception.message}")
|
66
|
-
Legion::Logging.warn("Backtrace: #{exception.backtrace}")
|
67
|
-
false
|
68
|
-
rescue LoadError => exception
|
69
|
-
Legion::Logging.fatal("Legion::Extension #{extension} failed to load, moving on without it")
|
70
|
-
Legion::Logging.warn("Extension failed with #{exception.message}")
|
71
|
-
Legion::Logging.warn("Backtrace: #{exception.backtrace}")
|
72
|
-
false
|
73
|
-
rescue StandardError => exception
|
74
|
-
Legion::Logging.fatal("Legion::Extension #{extension} failed to load, moving on without it")
|
75
|
-
Legion::Logging.fatal("#{extension} was caught by default")
|
76
|
-
Legion::Logging.warn("Extension failed with #{exception.message}")
|
77
|
-
Legion::Logging.warn("Backtrace: #{exception.backtrace}")
|
78
|
-
false
|
79
|
-
end
|
80
|
-
|
81
|
-
def gem_load(name)
|
82
|
-
search_name = 'lex-' + name.to_s
|
83
|
-
Legion::Logging.unknown search_name
|
84
|
-
gem_dir = Gem::Specification.find_by_name(search_name).gem_dir
|
85
|
-
Legion::Logging.unknown gem_dir
|
86
|
-
require "#{gem_dir}/lib/legion/extensions/#{name}"
|
87
|
-
true
|
88
|
-
rescue LoadError => ex
|
89
|
-
Legion::Logging.unknown ex.message
|
90
|
-
Legion::Logging.unknown ex.backtrace
|
91
|
-
Legion::Logging.warn "gem path: #{gem_dir}/lib/legion/extensions/#{name}"
|
92
|
-
false
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'legion/transport/messages/task_check_subtask'
|
4
|
-
require 'legion/transport/messages/task_update'
|
5
|
-
|
6
|
-
module Legion
|
7
|
-
module Runner
|
8
|
-
# Base running class that will run everything
|
9
|
-
class Runner
|
10
|
-
def initialize(klass, method, options = {}) # rubocop:disable Metrics/AbcSize
|
11
|
-
klass = Kernel.const_get(klass) if klass.is_a? String
|
12
|
-
result = if options[:args].nil?
|
13
|
-
klass.send(method)
|
14
|
-
else
|
15
|
-
klass.send(method, options[:args])
|
16
|
-
end
|
17
|
-
update_status(options[:task_id]) unless options[:task_id].nil?
|
18
|
-
Legion::Transport::Messages::TaskCheckSubtask.new(klass, method, result, options).publish
|
19
|
-
rescue StandardError => ex
|
20
|
-
Legion::Logging.error(ex.message)
|
21
|
-
Legion::Logging.warn(ex.backtrace)
|
22
|
-
return if options[:task_id].nil?
|
23
|
-
|
24
|
-
update_status(options[:task_id], 'task.exception', msg: ex.message)
|
25
|
-
end
|
26
|
-
|
27
|
-
def update_status(_task_id, status = 'task.completed', options = {})
|
28
|
-
Legion::Transport::Messages::TaskUpdate.new(options[:task_id], status, options).publish
|
29
|
-
# if Legion::Settings[:data][:connected]
|
30
|
-
# update_status_database(task_id, status)
|
31
|
-
# else
|
32
|
-
# update_status_rmq(task_id, status)
|
33
|
-
# end
|
34
|
-
end
|
35
|
-
|
36
|
-
def update_status_rmq(_task_id, status = 'task.completed', options = {})
|
37
|
-
Legion::Transport::Messages::TaskUpdate.new(options[:task_id], status).publish
|
38
|
-
end
|
39
|
-
|
40
|
-
def update_status_database(task_id, _status = 'task.completed', _options = {})
|
41
|
-
require 'legion/data/models/task'
|
42
|
-
task = Legion::Data::Model::Task[task_id]
|
43
|
-
task.update(status: 'task.completed')
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
# Status
|
50
|
-
# task.scheduled
|
51
|
-
# condition.queued
|
52
|
-
# condition.failed
|
53
|
-
# condition.succeeded
|
54
|
-
# condition.exception
|
55
|
-
# transformation.queued
|
56
|
-
# transformation.succeeded
|
57
|
-
# transformation.exception
|
58
|
-
# task.completed
|