legionio 0.4.3 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rspec.yml +45 -0
  3. data/.github/workflows/rubocop.yml +28 -0
  4. data/.github/workflows/sourcehawk-scan.yml +20 -0
  5. data/.gitignore +0 -0
  6. data/.rubocop.yml +2 -6
  7. data/CHANGELOG.md +2 -45
  8. data/CODE_OF_CONDUCT.md +75 -0
  9. data/CONTRIBUTING.md +55 -0
  10. data/Gemfile +7 -0
  11. data/INDIVIDUAL_CONTRIBUTOR_LICENSE.md +30 -0
  12. data/LICENSE +201 -0
  13. data/NOTICE.txt +9 -0
  14. data/README.md +13 -12
  15. data/SECURITY.md +9 -0
  16. data/attribution.txt +1 -0
  17. data/legionio.gemspec +19 -30
  18. data/lib/legion.rb +0 -1
  19. data/lib/legion/cli.rb +0 -0
  20. data/lib/legion/cli/chain.rb +0 -0
  21. data/lib/legion/cli/cohort.rb +0 -0
  22. data/lib/legion/cli/function.rb +0 -0
  23. data/lib/legion/cli/lex/actor.rb +0 -0
  24. data/lib/legion/cli/lex/exchange.rb +0 -0
  25. data/lib/legion/cli/lex/message.rb +0 -0
  26. data/lib/legion/cli/lex/queue.rb +0 -0
  27. data/lib/legion/cli/lex/runner.rb +0 -0
  28. data/lib/legion/cli/lex/templates/actor.erb +0 -0
  29. data/lib/legion/cli/lex/templates/actor_spec.erb +0 -0
  30. data/lib/legion/cli/lex/templates/base/bitbucket.yml.erb +0 -0
  31. data/lib/legion/cli/lex/templates/base/gemfile.erb +0 -0
  32. data/lib/legion/cli/lex/templates/base/gemspec.erb +0 -0
  33. data/lib/legion/cli/lex/templates/base/gitignore.erb +0 -0
  34. data/lib/legion/cli/lex/templates/base/lex.erb +0 -0
  35. data/lib/legion/cli/lex/templates/base/lex_spec.erb +0 -0
  36. data/lib/legion/cli/lex/templates/base/lic.erb +0 -0
  37. data/lib/legion/cli/lex/templates/base/rakefile.erb +0 -0
  38. data/lib/legion/cli/lex/templates/base/readme.md.erb +0 -0
  39. data/lib/legion/cli/lex/templates/base/rubocop.yml.erb +0 -0
  40. data/lib/legion/cli/lex/templates/base/spec_helper.rb.erb +0 -0
  41. data/lib/legion/cli/lex/templates/base/version.erb +0 -0
  42. data/lib/legion/cli/lex/templates/exchange.erb +0 -0
  43. data/lib/legion/cli/lex/templates/exchange_spec.erb +0 -0
  44. data/lib/legion/cli/lex/templates/message.erb +0 -0
  45. data/lib/legion/cli/lex/templates/message_spec.erb +0 -0
  46. data/lib/legion/cli/lex/templates/queue.erb +0 -0
  47. data/lib/legion/cli/lex/templates/queue_helper.erb +0 -0
  48. data/lib/legion/cli/lex/templates/queue_spec.erb +0 -0
  49. data/lib/legion/cli/lex/templates/runner.erb +0 -0
  50. data/lib/legion/cli/lex/templates/runner_spec.erb +0 -0
  51. data/lib/legion/cli/relationship.rb +0 -0
  52. data/lib/legion/cli/task.rb +0 -0
  53. data/lib/legion/cli/trigger.rb +2 -2
  54. data/lib/legion/cli/version.rb +0 -0
  55. data/lib/legion/extensions.rb +11 -1
  56. data/lib/legion/extensions/actors/base.rb +0 -0
  57. data/lib/legion/extensions/actors/defaults.rb +0 -0
  58. data/lib/legion/extensions/actors/every.rb +0 -0
  59. data/lib/legion/extensions/actors/loop.rb +0 -0
  60. data/lib/legion/extensions/actors/nothing.rb +0 -0
  61. data/lib/legion/extensions/actors/once.rb +2 -2
  62. data/lib/legion/extensions/actors/poll.rb +0 -0
  63. data/lib/legion/extensions/actors/subscription.rb +0 -0
  64. data/lib/legion/extensions/builders/actors.rb +0 -0
  65. data/lib/legion/extensions/builders/base.rb +0 -0
  66. data/lib/legion/extensions/builders/helpers.rb +0 -0
  67. data/lib/legion/extensions/builders/runners.rb +4 -0
  68. data/lib/legion/extensions/core.rb +1 -1
  69. data/lib/legion/extensions/data.rb +4 -1
  70. data/lib/legion/extensions/data/migrator.rb +6 -1
  71. data/lib/legion/extensions/data/model.rb +0 -0
  72. data/lib/legion/extensions/helpers/base.rb +0 -0
  73. data/lib/legion/extensions/helpers/cache.rb +0 -0
  74. data/lib/legion/extensions/helpers/core.rb +0 -0
  75. data/lib/legion/extensions/helpers/data.rb +0 -0
  76. data/lib/legion/extensions/helpers/lex.rb +0 -0
  77. data/lib/legion/extensions/helpers/logger.rb +0 -0
  78. data/lib/legion/extensions/helpers/task.rb +0 -0
  79. data/lib/legion/extensions/helpers/transport.rb +0 -0
  80. data/lib/legion/extensions/transport.rb +0 -0
  81. data/lib/legion/lex.rb +0 -0
  82. data/lib/legion/runner.rb +8 -6
  83. data/lib/legion/runner/log.rb +0 -0
  84. data/lib/legion/runner/status.rb +0 -0
  85. data/lib/legion/version.rb +1 -1
  86. data/sourcehawk.yml +4 -0
  87. metadata +36 -264
  88. data/.circleci/config.yml +0 -136
  89. data/.rspec +0 -2
  90. data/LICENSE.txt +0 -21
  91. data/Rakefile +0 -32
  92. data/bitbucket-pipelines.yml +0 -19
data/NOTICE.txt ADDED
@@ -0,0 +1,9 @@
1
+ LegionIO
2
+ Copyright 2021 Optum
3
+
4
+ Project Description:
5
+ ====================
6
+ LegionIO is an automation framework for create IFTTT style relationships, scheduling and managing sync and async tasks/jobs
7
+
8
+ Author(s):
9
+ Esity
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://bitbucket.org/legion-io/lex-http/src/master/) - Gives legion the ability to make http requests, [docs](https://legionio.atlassian.net/wiki/spaces/LEX/pages/12910593/Lex+Http)
30
- * [lex-influxdb](https://bitbucket.org/legion-io/lex-influxdb/src/master/) - Write, read, and manage influxdb nodes, [docs](https://legionio.atlassian.net/wiki/spaces/LEX/pages/614891774/Lex+Influxdb)
31
- * [lex-log](https://bitbucket.org/legion-io/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)
32
- * [lex-memcache](https://bitbucket.org/legion-io/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)
33
- * [lex-pihole](https://bitbucket.org/legion-io/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
34
- * [lex-ping](https://bitbucket.org/legion-io/lex-ping/src/master/) - You can ping things?, [docs](https://legionio.atlassian.net/wiki/spaces/LEX/pages/631373895/Lex+Ping)
35
- * [lex-pushover](https://bitbucket.org/legion-io/lex-pushover/src/master/) - Connects Legion to [Pushover](https://pushover.net/), [docs]()
36
- * [lex-redis](https://bitbucket.org/legion-io/lex-redis/src/master/) - similiar to lex-memcached but for redis
37
- * [lex-sleepiq](https://bitbucket.org/legion-io/lex-sleepiq/src/master/) - Control your SleepIQ bed with Legion!
38
- * [lex-ssh](https://bitbucket.org/legion-io/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)
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://bitbucket.org/legion-io/workspace/projects/LEX)
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://legionio.atlassian.net/wiki/spaces/LEX/pages/7864551/Extensions)
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
@@ -0,0 +1,9 @@
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+ | Version | Supported |
5
+ | ------- | ------------------ |
6
+ | 1.x.x | :white_check_mark: |
7
+
8
+ ## Reporting a Vulnerability
9
+ To be 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 = 'Legion Core Software to string it all together'
14
- spec.description = 'Legion Core runs Legion Framwork'
15
- spec.homepage = 'https://bitbucket.org/legion-io/legion/'
16
- spec.metadata['source_code_uri'] = 'https://bitbucket.org/legion-io/legion/src/master/'
17
- spec.metadata['documentation_uri'] = 'https://legionio.atlassian.net/wiki/spaces/LEGION/overview'
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-exceptions'
39
- spec.add_dependency 'legion-json'
40
- spec.add_dependency 'legion-logging'
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
@@ -1,7 +1,6 @@
1
1
  Process.setproctitle('Legion')
2
2
  require 'concurrent'
3
3
  require 'securerandom'
4
- require 'legion/exceptions'
5
4
  require 'legion/version'
6
5
  require 'legion/process'
7
6
  require 'legion/service'
data/lib/legion/cli.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
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -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
 
File without changes
@@ -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 if disabled?
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 if disabled?
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 # rubocop:disable Metrics/AbcSize
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
- runner_class: runner_class,
16
- parent_id: parent_id, master_id: master_id, task_id: task_id, **opts
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
- else
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,