legionio 0.4.3 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rspec.yml +45 -0
- data/.github/workflows/rubocop.yml +28 -0
- data/.github/workflows/sourcehawk-scan.yml +20 -0
- data/.gitignore +0 -0
- data/.rubocop.yml +2 -6
- data/CHANGELOG.md +2 -45
- data/CODE_OF_CONDUCT.md +75 -0
- data/CONTRIBUTING.md +55 -0
- data/Gemfile +7 -0
- data/INDIVIDUAL_CONTRIBUTOR_LICENSE.md +30 -0
- data/LICENSE +201 -0
- data/NOTICE.txt +9 -0
- data/README.md +13 -12
- data/SECURITY.md +9 -0
- data/attribution.txt +1 -0
- data/legionio.gemspec +19 -30
- data/lib/legion.rb +0 -1
- data/lib/legion/cli.rb +0 -0
- data/lib/legion/cli/chain.rb +0 -0
- data/lib/legion/cli/cohort.rb +0 -0
- data/lib/legion/cli/function.rb +0 -0
- data/lib/legion/cli/lex/actor.rb +0 -0
- data/lib/legion/cli/lex/exchange.rb +0 -0
- data/lib/legion/cli/lex/message.rb +0 -0
- data/lib/legion/cli/lex/queue.rb +0 -0
- data/lib/legion/cli/lex/runner.rb +0 -0
- data/lib/legion/cli/lex/templates/actor.erb +0 -0
- data/lib/legion/cli/lex/templates/actor_spec.erb +0 -0
- data/lib/legion/cli/lex/templates/base/bitbucket.yml.erb +0 -0
- data/lib/legion/cli/lex/templates/base/gemfile.erb +0 -0
- data/lib/legion/cli/lex/templates/base/gemspec.erb +0 -0
- data/lib/legion/cli/lex/templates/base/gitignore.erb +0 -0
- data/lib/legion/cli/lex/templates/base/lex.erb +0 -0
- data/lib/legion/cli/lex/templates/base/lex_spec.erb +0 -0
- data/lib/legion/cli/lex/templates/base/lic.erb +0 -0
- data/lib/legion/cli/lex/templates/base/rakefile.erb +0 -0
- data/lib/legion/cli/lex/templates/base/readme.md.erb +0 -0
- data/lib/legion/cli/lex/templates/base/rubocop.yml.erb +0 -0
- data/lib/legion/cli/lex/templates/base/spec_helper.rb.erb +0 -0
- data/lib/legion/cli/lex/templates/base/version.erb +0 -0
- data/lib/legion/cli/lex/templates/exchange.erb +0 -0
- data/lib/legion/cli/lex/templates/exchange_spec.erb +0 -0
- data/lib/legion/cli/lex/templates/message.erb +0 -0
- data/lib/legion/cli/lex/templates/message_spec.erb +0 -0
- data/lib/legion/cli/lex/templates/queue.erb +0 -0
- data/lib/legion/cli/lex/templates/queue_helper.erb +0 -0
- data/lib/legion/cli/lex/templates/queue_spec.erb +0 -0
- data/lib/legion/cli/lex/templates/runner.erb +0 -0
- data/lib/legion/cli/lex/templates/runner_spec.erb +0 -0
- data/lib/legion/cli/relationship.rb +0 -0
- data/lib/legion/cli/task.rb +0 -0
- data/lib/legion/cli/trigger.rb +2 -2
- data/lib/legion/cli/version.rb +0 -0
- data/lib/legion/extensions.rb +11 -1
- data/lib/legion/extensions/actors/base.rb +0 -0
- data/lib/legion/extensions/actors/defaults.rb +0 -0
- data/lib/legion/extensions/actors/every.rb +0 -0
- data/lib/legion/extensions/actors/loop.rb +0 -0
- data/lib/legion/extensions/actors/nothing.rb +0 -0
- data/lib/legion/extensions/actors/once.rb +2 -2
- data/lib/legion/extensions/actors/poll.rb +0 -0
- data/lib/legion/extensions/actors/subscription.rb +0 -0
- data/lib/legion/extensions/builders/actors.rb +0 -0
- data/lib/legion/extensions/builders/base.rb +0 -0
- data/lib/legion/extensions/builders/helpers.rb +0 -0
- data/lib/legion/extensions/builders/runners.rb +4 -0
- data/lib/legion/extensions/core.rb +1 -1
- data/lib/legion/extensions/data.rb +4 -1
- data/lib/legion/extensions/data/migrator.rb +6 -1
- data/lib/legion/extensions/data/model.rb +0 -0
- data/lib/legion/extensions/helpers/base.rb +0 -0
- data/lib/legion/extensions/helpers/cache.rb +0 -0
- data/lib/legion/extensions/helpers/core.rb +0 -0
- data/lib/legion/extensions/helpers/data.rb +0 -0
- data/lib/legion/extensions/helpers/lex.rb +0 -0
- data/lib/legion/extensions/helpers/logger.rb +0 -0
- data/lib/legion/extensions/helpers/task.rb +0 -0
- data/lib/legion/extensions/helpers/transport.rb +0 -0
- data/lib/legion/extensions/transport.rb +0 -0
- data/lib/legion/lex.rb +0 -0
- data/lib/legion/runner.rb +8 -6
- data/lib/legion/runner/log.rb +0 -0
- data/lib/legion/runner/status.rb +0 -0
- data/lib/legion/version.rb +1 -1
- data/sourcehawk.yml +4 -0
- metadata +36 -264
- data/.circleci/config.yml +0 -136
- data/.rspec +0 -2
- data/LICENSE.txt +0 -21
- data/Rakefile +0 -32
- data/bitbucket-pipelines.yml +0 -19
data/NOTICE.txt
ADDED
data/README.md
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
LegionIO is a framework for automating and connecting things. You can see all the docs inside confluence
|
4
4
|
https://legionio.atlassian.net/wiki/spaces/LEGION/overview
|
5
5
|
https://legionio.atlassian.net/wiki/spaces/LEX/pages/7864551/Extensions
|
6
|
+
*Soon to be migrated to GitHub Wiki*
|
6
7
|
|
7
8
|
### What does it do?
|
8
9
|
LegionIO is an async job engine designed for scheduling tasks and creating relationships between things that wouldn't
|
@@ -26,21 +27,21 @@ After installing gem you can use the commands `legionio` to start legion, `legio
|
|
26
27
|
and `lex_gen` to generate a new legion extension
|
27
28
|
|
28
29
|
### Example Legion Extensions(LEX)
|
29
|
-
* [lex-http](https://
|
30
|
-
* [lex-influxdb](https://
|
31
|
-
* [lex-log](https://
|
32
|
-
* [lex-memcache](https://
|
33
|
-
* [lex-pihole](https://
|
34
|
-
* [lex-ping](https://
|
35
|
-
* [lex-pushover](https://
|
36
|
-
* [lex-redis](https://
|
37
|
-
* [lex-sleepiq](https://
|
38
|
-
* [lex-ssh](https://
|
30
|
+
* [lex-http](https://github.com/LegionIO/lex-http/src/master/) - Gives legion the ability to make http requests, [docs](https://legionio.atlassian.net/wiki/spaces/LEX/pages/12910593/Lex+Http)
|
31
|
+
* [lex-influxdb](https://github.com/LegionIO/lex-influxdb/src/master/) - Write, read, and manage influxdb nodes, [docs](https://legionio.atlassian.net/wiki/spaces/LEX/pages/614891774/Lex+Influxdb)
|
32
|
+
* [lex-log](https://github.com/LegionIO/lex-log/src/master/) - Send log items to either stdout or a file with lex-log, [docs](https://legionio.atlassian.net/wiki/spaces/LEX/pages/614858995/Lex+Log)
|
33
|
+
* [lex-memcache](https://github.com/LegionIO/lex-memcached/src/master/) - run memcached commands like set, add, append, delete, flush, reset_stats against memcached servers, [docs](https://legionio.atlassian.net/wiki/spaces/LEX/pages/614858753/Lex+Memcached)
|
34
|
+
* [lex-pihole](https://github.com/LegionIO/lex-pihole/src/master/) - Allows Legion to interact with [Pi-Hole](https://pi-hole.net/). Can do things like get status, add/remove domains from the list, etc
|
35
|
+
* [lex-ping](https://github.com/LegionIO/lex-ping/src/master/) - You can ping things?, [docs](https://legionio.atlassian.net/wiki/spaces/LEX/pages/631373895/Lex+Ping)
|
36
|
+
* [lex-pushover](https://github.com/LegionIO/lex-pushover/src/master/) - Connects Legion to [Pushover](https://pushover.net/), [docs]()
|
37
|
+
* [lex-redis](https://github.com/LegionIO/lex-redis/src/master/) - similiar to lex-memcached but for redis
|
38
|
+
* [lex-sleepiq](https://github.com/LegionIO/lex-sleepiq/src/master/) - Control your SleepIQ bed with Legion!
|
39
|
+
* [lex-ssh](https://github.com/LegionIO/lex-ssh/src/master/) - Send commands to a server via SSH in an async fashion, [docs](https://legionio.atlassian.net/wiki/spaces/LEX/pages/614891551/Lex+SSH)
|
39
40
|
|
40
41
|
Bitbucket repos for extensions that are active or being worked on
|
41
|
-
[lex list](https://
|
42
|
+
[lex list](https://github.com/LegionIO/workspace/projects/LEX)
|
42
43
|
A nice list in the wiki to view all the extensions, their docs and status
|
43
|
-
[Legion Extensions](https://
|
44
|
+
[Legion Extensions](https://github.com/topics/legionio?l=ruby)
|
44
45
|
|
45
46
|
### Scheduling Tasks
|
46
47
|
1) Ensure you have the Legion::Data gem installed and configured
|
data/SECURITY.md
ADDED
data/attribution.txt
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Add attributions here.
|
data/legionio.gemspec
CHANGED
@@ -10,22 +10,29 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.authors = ['Esity']
|
11
11
|
spec.email = ['matthewdiverson@gmail.com']
|
12
12
|
|
13
|
-
spec.summary = '
|
14
|
-
spec.description = '
|
15
|
-
spec.homepage = 'https://
|
16
|
-
spec.
|
17
|
-
spec.
|
18
|
-
spec.metadata['bug_tracker_uri'] = 'https://legionio.atlassian.net/browse/LEG'
|
19
|
-
spec.license = 'MIT'
|
13
|
+
spec.summary = 'The primary gem to run the LegionIO Framework'
|
14
|
+
spec.description = 'LegionIO is an extensible framework for running, scheduling and building relationships of tasks in a concurrent matter'
|
15
|
+
spec.homepage = 'https://github.com/Optum/LegionIO'
|
16
|
+
spec.license = 'Apache-2.0'
|
17
|
+
spec.require_paths = ['lib']
|
20
18
|
spec.required_ruby_version = '>= 2.5.0'
|
21
19
|
|
20
|
+
spec.metadata = {
|
21
|
+
'bug_tracker_uri' => 'https://github.com/Optum/LegionIO/issues',
|
22
|
+
'changelog_uri' => 'https://github.com/Optum/LegionIO/src/main/CHANGELOG.md',
|
23
|
+
'documentation_uri' => 'https://github.com/Optum/LegionIO',
|
24
|
+
'homepage_uri' => 'https://github.com/Optum/LegionIO',
|
25
|
+
'source_code_uri' => 'https://github.com/Optum/LegionIO',
|
26
|
+
'wiki_uri' => 'https://github.com/Optum/LegionIO'
|
27
|
+
}
|
28
|
+
|
22
29
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
23
30
|
f.match(%r{^(test|spec|features)/})
|
24
31
|
end
|
32
|
+
spec.test_files = spec.files.select { |p| p =~ %r{^test/.*_test.rb} }
|
25
33
|
|
26
34
|
spec.bindir = 'exe'
|
27
35
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
-
spec.require_paths = ['lib']
|
29
36
|
|
30
37
|
spec.add_dependency 'concurrent-ruby', '>= 1.1.7'
|
31
38
|
spec.add_dependency 'concurrent-ruby-ext', '>= 1.1.7'
|
@@ -33,32 +40,14 @@ Gem::Specification.new do |spec|
|
|
33
40
|
spec.add_dependency 'oj', '>= 3.10'
|
34
41
|
spec.add_dependency 'thor', '>= 1'
|
35
42
|
|
36
|
-
spec.add_dependency 'legion-cache'
|
43
|
+
spec.add_dependency 'legion-cache', '>= 0.2.0'
|
37
44
|
spec.add_dependency 'legion-crypt', '>= 0.2.0'
|
38
|
-
spec.add_dependency 'legion-
|
39
|
-
spec.add_dependency 'legion-
|
40
|
-
spec.add_dependency 'legion-
|
41
|
-
spec.add_dependency 'legion-settings'
|
45
|
+
spec.add_dependency 'legion-json', '>= 0.2.0'
|
46
|
+
spec.add_dependency 'legion-logging', '>= 0.2.0'
|
47
|
+
spec.add_dependency 'legion-settings', '>= 0.2.0'
|
42
48
|
spec.add_dependency 'legion-transport', '>= 1.1.9'
|
43
49
|
|
44
50
|
spec.add_dependency 'lex-node'
|
45
51
|
|
46
|
-
spec.add_development_dependency 'codecov'
|
47
52
|
spec.add_development_dependency 'legion-data'
|
48
|
-
spec.add_development_dependency 'rake'
|
49
|
-
spec.add_development_dependency 'rspec'
|
50
|
-
spec.add_development_dependency 'rspec_junit_formatter'
|
51
|
-
spec.add_development_dependency 'rubocop'
|
52
|
-
spec.add_development_dependency 'rubocop-rake'
|
53
|
-
spec.add_development_dependency 'rubocop-rspec'
|
54
|
-
spec.add_development_dependency 'simplecov'
|
55
|
-
|
56
|
-
spec.add_development_dependency 'lex-conditioner'
|
57
|
-
spec.add_development_dependency 'lex-health'
|
58
|
-
spec.add_development_dependency 'lex-http'
|
59
|
-
spec.add_development_dependency 'lex-lex'
|
60
|
-
spec.add_development_dependency 'lex-log'
|
61
|
-
spec.add_development_dependency 'lex-scheduler'
|
62
|
-
spec.add_development_dependency 'lex-tasker'
|
63
|
-
spec.add_development_dependency 'lex-transformer'
|
64
53
|
end
|
data/lib/legion.rb
CHANGED
data/lib/legion/cli.rb
CHANGED
File without changes
|
data/lib/legion/cli/chain.rb
CHANGED
File without changes
|
data/lib/legion/cli/cohort.rb
CHANGED
File without changes
|
data/lib/legion/cli/function.rb
CHANGED
File without changes
|
data/lib/legion/cli/lex/actor.rb
CHANGED
File without changes
|
File without changes
|
File without changes
|
data/lib/legion/cli/lex/queue.rb
CHANGED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/lib/legion/cli/task.rb
CHANGED
File without changes
|
data/lib/legion/cli/trigger.rb
CHANGED
@@ -65,7 +65,7 @@ module Legion
|
|
65
65
|
|
66
66
|
status = options[:delay].zero? ? 'task.queued' : 'task.delayed'
|
67
67
|
task = generate_task_id(function_id: trigger_function.values[:id], status: status, runner_id: trigger_runner.values[:id], args: payload,
|
68
|
-
delay: options[:delay])
|
68
|
+
delay: options[:delay])
|
69
69
|
|
70
70
|
unless options[:delay].zero?
|
71
71
|
say "Task: #{task[:task_id]} is queued and will be run in #{options[:delay]}s"
|
@@ -74,7 +74,7 @@ delay: options[:delay])
|
|
74
74
|
|
75
75
|
routing_key = "#{trigger_extension.values[:exchange]}.#{trigger_runner.values[:queue]}.#{trigger_function.values[:name]}"
|
76
76
|
exchange = Legion::Transport::Messages::Dynamic.new(function: trigger_function.values[:name], function_id: trigger_function.values[:id],
|
77
|
-
routing_key: routing_key, args: payload)
|
77
|
+
routing_key: routing_key, args: payload)
|
78
78
|
exchange.options[:task_id] = task[:task_id]
|
79
79
|
exchange.publish if options[:delay].zero?
|
80
80
|
|
data/lib/legion/cli/version.rb
CHANGED
File without changes
|
data/lib/legion/extensions.rb
CHANGED
@@ -59,10 +59,15 @@ module Legion
|
|
59
59
|
Legion::Logging.info "#{@extensions.count} extensions loaded with subscription:#{@subscription_tasks.count},every:#{@timer_tasks.count},poll:#{@poll_tasks.count},once:#{@once_tasks.count},loop:#{@loop_tasks.count}"
|
60
60
|
end
|
61
61
|
|
62
|
-
def load_extension(extension, values)
|
62
|
+
def load_extension(extension, values) # rubocop:disable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity, Metrics/AbcSize
|
63
63
|
return unless gem_load(values[:gem_name], extension)
|
64
64
|
|
65
65
|
extension = Kernel.const_get(values[:extension_class])
|
66
|
+
extension.extend Legion::Extensions::Core unless extension.singleton_class.included_modules.include? Legion::Extensions::Core
|
67
|
+
|
68
|
+
min_version = Legion::Settings[:extensions][values[:extension_name]][:min_version] || nil
|
69
|
+
Legion::Logging.fatal values if min_version.is_a?(String) && Gem::Version.new(values[:version]) >= Gem::Version.new(min_version)
|
70
|
+
|
66
71
|
if extension.data_required? && Legion::Settings[:data][:connected] == false
|
67
72
|
Legion::Logging.warn "#{values[:extension_name]} requires Legion::Data but isn't enabled, skipping"
|
68
73
|
return false
|
@@ -73,6 +78,11 @@ module Legion
|
|
73
78
|
return false
|
74
79
|
end
|
75
80
|
|
81
|
+
if extension.crypt_required? && Legion::Settings[:crypt][:cs].nil?
|
82
|
+
Legion::Logging.warn "#{values[:extension_name]} requires Legion::Crypt but isn't ready, skipping"
|
83
|
+
return false
|
84
|
+
end
|
85
|
+
|
76
86
|
if extension.vault_required? && Legion::Settings[:crypt][:vault][:connected] == false
|
77
87
|
Legion::Logging.warn "#{values[:extension_name]} requires Legion::Crypt::Vault but isn't enabled, skipping"
|
78
88
|
return false
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -7,7 +7,7 @@ module Legion
|
|
7
7
|
include Legion::Extensions::Actors::Base
|
8
8
|
|
9
9
|
def initialize
|
10
|
-
return
|
10
|
+
return unless enabled?
|
11
11
|
|
12
12
|
if respond_to? :functions
|
13
13
|
functions.each do
|
@@ -30,7 +30,7 @@ module Legion
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def cancel
|
33
|
-
return
|
33
|
+
return unless enabled?
|
34
34
|
|
35
35
|
@task.cancel unless @task.cancelled?
|
36
36
|
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -31,6 +31,8 @@ module Legion
|
|
31
31
|
class_methods: {}
|
32
32
|
}
|
33
33
|
|
34
|
+
@runners[runner_name.to_sym][:scheduled_tasks] = loaded_runner.scheduled_tasks if loaded_runner.method_defined? :scheduled_tasks
|
35
|
+
|
34
36
|
if settings.key?(:runners) && settings[:runners].key?(runner_name.to_sym)
|
35
37
|
@runners[runner_name.to_sym][:desc] = settings[:runners][runner_name.to_sym][:desc]
|
36
38
|
end
|
@@ -42,6 +44,8 @@ module Legion
|
|
42
44
|
end
|
43
45
|
|
44
46
|
loaded_runner.methods(false).each do |runner_method|
|
47
|
+
next if %i[scheduled_tasks runner_description].include? runner_method
|
48
|
+
|
45
49
|
@runners[runner_name.to_sym][:class_methods][runner_method] = {
|
46
50
|
args: loaded_runner.method(runner_method).parameters
|
47
51
|
}
|
@@ -84,7 +84,7 @@ module Legion
|
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
87
|
-
def build_settings
|
87
|
+
def build_settings
|
88
88
|
if Legion::Settings[:extensions].key?(lex_name.to_sym)
|
89
89
|
Legion::Settings[:default_extension_settings].each do |key, value|
|
90
90
|
Legion::Settings[:extensions][lex_name.to_sym][key.to_sym] = if Legion::Settings[:extensions][lex_name.to_sym].key?(key.to_sym)
|
@@ -8,6 +8,7 @@ module Legion
|
|
8
8
|
include Legion::Extensions::Helpers::Logger
|
9
9
|
|
10
10
|
def build
|
11
|
+
Legion::Logging.fatal 'testing inside run'
|
11
12
|
@models = []
|
12
13
|
@migrations = []
|
13
14
|
if Dir[File.expand_path("#{data_path}/migrations/*.rb")].count.positive?
|
@@ -43,10 +44,12 @@ module Legion
|
|
43
44
|
end
|
44
45
|
|
45
46
|
def migrate_class
|
46
|
-
@migrate_class ||= Legion::Extensions::Data::Migrator.new(migrations_path, lex_class.to_s)
|
47
|
+
@migrate_class ||= Legion::Extensions::Data::Migrator.new(migrations_path, lex_class.to_s, lex_name)
|
47
48
|
end
|
48
49
|
|
49
50
|
def run
|
51
|
+
Legion::Logging.fatal 'testing inside run'
|
52
|
+
|
50
53
|
return true if migrate_class.is_current?
|
51
54
|
|
52
55
|
log.debug('Running LEX schema migrator')
|
@@ -4,7 +4,8 @@ module Legion
|
|
4
4
|
module Extensions
|
5
5
|
module Data
|
6
6
|
class Migrator < Sequel::IntegerMigrator
|
7
|
-
def initialize(path, extension, **)
|
7
|
+
def initialize(path, extension, _lex_name, **)
|
8
|
+
Legion::Logging.fatal @extension
|
8
9
|
@path = path
|
9
10
|
@extension = extension
|
10
11
|
super(Legion::Data::Connection.sequel, path)
|
@@ -19,6 +20,10 @@ module Legion
|
|
19
20
|
end
|
20
21
|
|
21
22
|
def schema_dataset
|
23
|
+
dataset = Legion::Data::Connection.sequel.from(default_schema_table).where(namespace: @extension)
|
24
|
+
return dataset unless dataset.count.positive?
|
25
|
+
|
26
|
+
Legion::Logging.unknown Legion::Data::Model::Extension.insert(active: 1, namespace: @extension, extension: lex_name)
|
22
27
|
Legion::Data::Connection.sequel.from(default_schema_table).where(namespace: @extension)
|
23
28
|
end
|
24
29
|
alias ds schema_dataset
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/lib/legion/lex.rb
CHANGED
File without changes
|
data/lib/legion/runner.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'legion/exceptions/handled_task'
|
2
1
|
require_relative 'runner/log'
|
3
2
|
require_relative 'runner/status'
|
4
3
|
require 'legion/transport'
|
@@ -6,14 +5,14 @@ require 'legion/transport/messages/check_subtask'
|
|
6
5
|
|
7
6
|
module Legion
|
8
7
|
module Runner
|
9
|
-
def self.run(runner_class:, function:, task_id: nil, args: nil, check_subtask: true, generate_task: true, parent_id: nil, master_id: nil, **opts) # rubocop:disable Metrics/ParameterLists
|
8
|
+
def self.run(runner_class:, function:, task_id: nil, args: nil, check_subtask: true, generate_task: true, parent_id: nil, master_id: nil, catch_exceptions: false, **opts) # rubocop:disable Layout/LineLength, Metrics/CyclomaticComplexity, Metrics/ParameterLists
|
10
9
|
runner_class = Kernel.const_get(runner_class) if runner_class.is_a? String
|
11
10
|
|
12
11
|
if task_id.nil? && generate_task
|
13
12
|
task_gen = Legion::Runner::Status.generate_task_id(
|
14
13
|
function: function,
|
15
|
-
|
16
|
-
|
14
|
+
runner_class: runner_class,
|
15
|
+
parent_id: parent_id, master_id: master_id, task_id: task_id, **opts
|
17
16
|
)
|
18
17
|
task_id = task_gen[:task_id] unless task_gen.nil?
|
19
18
|
end
|
@@ -23,6 +22,9 @@ module Legion
|
|
23
22
|
args[:master_id] = master_id unless master_id.nil?
|
24
23
|
args[:parent_id] = parent_id unless parent_id.nil?
|
25
24
|
|
25
|
+
# result = Fiber.new { Fiber.yield runner_class.send(function, **args) }
|
26
|
+
raise 'No Function defined' if function.nil?
|
27
|
+
|
26
28
|
result = runner_class.send(function, **args)
|
27
29
|
rescue Legion::Exception::HandledTask
|
28
30
|
status = 'task.exception'
|
@@ -38,9 +40,9 @@ module Legion
|
|
38
40
|
check_subtask: check_subtask)
|
39
41
|
status = 'task.exception'
|
40
42
|
result = { success: false, status: status, error: { message: e.message, backtrace: e.backtrace } }
|
41
|
-
|
42
|
-
status = 'task.completed'
|
43
|
+
raise e unless catch_exceptions
|
43
44
|
ensure
|
45
|
+
status = 'task.completed' if status.nil?
|
44
46
|
Legion::Runner::Status.update(task_id: task_id, status: status) unless task_id.nil?
|
45
47
|
if check_subtask && status == 'task.completed'
|
46
48
|
Legion::Transport::Messages::CheckSubtask.new(runner_class: runner_class,
|