legionio 0.3.0 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. metadata +8 -60
  3. data/.circleci/config.yml +0 -119
  4. data/.gitignore +0 -14
  5. data/.rspec +0 -2
  6. data/.rubocop.yml +0 -89
  7. data/CHANGELOG.md +0 -16
  8. data/Gemfile +0 -3
  9. data/LICENSE.txt +0 -21
  10. data/README.md +0 -46
  11. data/Rakefile +0 -38
  12. data/bin/console +0 -16
  13. data/bin/legion +0 -50
  14. data/bin/setup +0 -8
  15. data/bin/test +0 -32
  16. data/bitbucket-pipelines.yml +0 -55
  17. data/exe/legion +0 -50
  18. data/legion.gemspec +0 -59
  19. data/lib/legion.rb +0 -21
  20. data/lib/legion/exceptions/handled_task.rb +0 -6
  21. data/lib/legion/exceptions/invalidjson.rb +0 -5
  22. data/lib/legion/exceptions/missingargument.rb +0 -6
  23. data/lib/legion/exceptions/wrongtype.rb +0 -10
  24. data/lib/legion/exceptions/wrongtypes/array.rb +0 -8
  25. data/lib/legion/exceptions/wrongtypes/hash.rb +0 -8
  26. data/lib/legion/exceptions/wrongtypes/integer.rb +0 -8
  27. data/lib/legion/exceptions/wrongtypes/string.rb +0 -8
  28. data/lib/legion/extensions.rb +0 -164
  29. data/lib/legion/extensions/actors/base.rb +0 -49
  30. data/lib/legion/extensions/actors/every.rb +0 -48
  31. data/lib/legion/extensions/actors/loop.rb +0 -32
  32. data/lib/legion/extensions/actors/nothing.rb +0 -15
  33. data/lib/legion/extensions/actors/once.rb +0 -40
  34. data/lib/legion/extensions/actors/poll.rb +0 -88
  35. data/lib/legion/extensions/actors/subscription.rb +0 -130
  36. data/lib/legion/extensions/builders/actors.rb +0 -61
  37. data/lib/legion/extensions/builders/base.rb +0 -36
  38. data/lib/legion/extensions/builders/helpers.rb +0 -24
  39. data/lib/legion/extensions/builders/runners.rb +0 -53
  40. data/lib/legion/extensions/core.rb +0 -94
  41. data/lib/legion/extensions/data.rb +0 -10
  42. data/lib/legion/extensions/helpers/base.rb +0 -82
  43. data/lib/legion/extensions/helpers/core.rb +0 -41
  44. data/lib/legion/extensions/helpers/lex.rb +0 -20
  45. data/lib/legion/extensions/helpers/logger.rb +0 -47
  46. data/lib/legion/extensions/helpers/task.rb +0 -40
  47. data/lib/legion/extensions/helpers/transport.rb +0 -43
  48. data/lib/legion/extensions/transport.rb +0 -155
  49. data/lib/legion/process.rb +0 -126
  50. data/lib/legion/runner.rb +0 -55
  51. data/lib/legion/runner/log.rb +0 -10
  52. data/lib/legion/runner/status.rb +0 -69
  53. data/lib/legion/service.rb +0 -78
  54. data/lib/legion/supervision.rb +0 -15
  55. data/lib/legion/version.rb +0 -3
  56. data/settings/client.json +0 -23
@@ -1,36 +0,0 @@
1
- module Legion
2
- module Extensions
3
- module Builder
4
- module Base
5
- def find_files(name, path = extension_path)
6
- files = []
7
- return files unless Dir.exist? "#{path}/#{name}"
8
-
9
- Dir["#{path}/#{name}/*.rb"].each do |file|
10
- files.push(file)
11
- end
12
- files
13
- end
14
-
15
- def require_files(files)
16
- files.each { |file| require file }
17
- end
18
-
19
- def const_defined_two?(item, root = Kernel)
20
- root.const_defined?(item.to_s)
21
- end
22
-
23
- def define_constant_two(item, root: Kernel, type: Module)
24
- return true if const_defined?(item, root: root)
25
-
26
- root.const_set(item.to_s, type.new)
27
- end
28
-
29
- def define_get(item, root: Kernel, type: Module)
30
- define_constant_two(item, root: root, type: type) if const_defined_two?(item, root: root)
31
- root.const_get(item)
32
- end
33
- end
34
- end
35
- end
36
- end
@@ -1,24 +0,0 @@
1
- require_relative 'base'
2
-
3
- module Legion
4
- module Extensions
5
- module Builder
6
- module Helpers
7
- include Legion::Extensions::Builder::Base
8
-
9
- def build_helpers
10
- @helpers ||= []
11
- @helpers.push(require_files(helper_files))
12
- end
13
-
14
- def helper_files
15
- @helper_files ||= find_files('helpers')
16
- end
17
-
18
- def helpers
19
- @helpers
20
- end
21
- end
22
- end
23
- end
24
- end
@@ -1,53 +0,0 @@
1
- require_relative 'base'
2
-
3
- module Legion
4
- module Extensions
5
- module Builder
6
- module Runners
7
- include Legion::Extensions::Builder::Base
8
-
9
- attr_reader :runners
10
-
11
- def build_runners
12
- @runners = {}
13
- lex_class.const_set('Runners', Module.new) unless lex_class.const_defined?('Runners')
14
- require_files(runner_files)
15
- build_runner_list
16
- end
17
-
18
- def build_runner_list
19
- runner_files.each do |file|
20
- runner_name = file.split('/').last.sub('.rb', '')
21
- runner_class = "#{lex_class}::Runners::#{runner_name.split('_').collect(&:capitalize).join}"
22
- loaded_runner = Kernel.const_get(runner_class)
23
- @runners[runner_name.to_sym] = {
24
- extension: lex_class.to_s.downcase,
25
- extension_name: extension_name,
26
- extension_class: lex_class,
27
- runner_name: runner_name,
28
- runner_class: runner_class,
29
- runner_path: file,
30
- class_methods: {}
31
- }
32
-
33
- loaded_runner.public_instance_methods(false).each do |runner_method|
34
- @runners[runner_name.to_sym][:class_methods][runner_method] = {
35
- args: loaded_runner.instance_method(runner_method).parameters
36
- }
37
- end
38
-
39
- loaded_runner.methods(false).each do |runner_method|
40
- @runners[runner_name.to_sym][:class_methods][runner_method] = {
41
- args: loaded_runner.method(runner_method).parameters
42
- }
43
- end
44
- end
45
- end
46
-
47
- def runner_files
48
- @runner_files ||= find_files('runners')
49
- end
50
- end
51
- end
52
- end
53
- end
@@ -1,94 +0,0 @@
1
- require_relative 'builders/actors'
2
- require_relative 'builders/helpers'
3
- require_relative 'builders/runners'
4
-
5
- require_relative 'helpers/core'
6
- require_relative 'helpers/task'
7
- require_relative 'helpers/logger'
8
- require_relative 'helpers/lex'
9
- require_relative 'helpers/transport'
10
-
11
- require_relative 'actors/base'
12
- require_relative 'actors/every'
13
- require_relative 'actors/loop'
14
- require_relative 'actors/once'
15
- require_relative 'actors/poll'
16
- require_relative 'actors/subscription'
17
- require_relative 'actors/nothing'
18
-
19
- module Legion
20
- module Extensions
21
- module Core
22
- include Legion::Extensions::Helpers::Transport
23
- include Legion::Extensions::Helpers::Lex
24
-
25
- include Legion::Extensions::Builder::Runners
26
- include Legion::Extensions::Builder::Helpers
27
- include Legion::Extensions::Builder::Actors
28
-
29
- def autobuild
30
- @actors = {}
31
- @meta_actors = {}
32
- @runners = {}
33
- @helpers = []
34
-
35
- @queues = {}
36
- @exchanges = {}
37
- @messages = {}
38
- build_settings
39
- build_transport
40
- build_helpers
41
- build_runners
42
- build_actors
43
- end
44
-
45
- def build_transport
46
- if File.exist? "#{extension_path}/transport/autobuild.rb"
47
- require "#{extension_path}/transport/autobuild"
48
- extension_class::Transport::AutoBuild.build
49
- log.warn 'still using transport::autobuild, please upgrade'
50
- elsif File.exist? "#{extension_path}/transport.rb"
51
- require "#{extension_path}/transport"
52
- extension_class::Transport.build
53
- else
54
- auto_generate_transport
55
- extension_class::Transport.build
56
- end
57
- end
58
-
59
- def build_settings # rubocop:disable Metrics/AbcSize
60
- if Legion::Settings[:extensions].key?(lex_name.to_sym)
61
- Legion::Settings[:default_extension_settings].each do |key, value|
62
- Legion::Settings[:extensions][lex_name.to_sym][key.to_sym] = if Legion::Settings[:extensions][lex_name.to_sym].key?(key.to_sym)
63
- value.merge(Legion::Settings[:extensions][lex_name.to_sym][key.to_sym])
64
- else
65
- value
66
- end
67
- end
68
- else
69
- Legion::Settings[:extensions][lex_name.to_sym] = Legion::Settings[:default_extension_settings]
70
- end
71
-
72
- default_settings.each do |key, value|
73
- Legion::Settings[:extensions][lex_name.to_sym][key.to_sym] = if Legion::Settings[:extensions][lex_name.to_sym].key?(key.to_sym)
74
- value.merge(Legion::Settings[:extensions][lex_name.to_sym][key.to_sym])
75
- else
76
- value
77
- end
78
- end
79
- end
80
-
81
- def default_settings
82
- {}
83
- end
84
-
85
- def auto_generate_transport
86
- require 'legion/extensions/transport'
87
- log.debug 'running meta magic to generate a transport base class'
88
- return if Kernel.const_defined? "#{lex_class}::Transport"
89
-
90
- Kernel.const_get(lex_class.to_s).const_set('Transport', Module.new { extend Legion::Extensions::Transport })
91
- end
92
- end
93
- end
94
- end
@@ -1,10 +0,0 @@
1
- module Legion
2
- module Extensions
3
- module Data
4
- def build
5
- @models = []
6
- @migrations = []
7
- end
8
- end
9
- end
10
- end
@@ -1,82 +0,0 @@
1
- module Legion
2
- module Extensions
3
- module Helpers
4
- module Base
5
- def lex_class
6
- @lex_class ||= Kernel.const_get(calling_class_array[0..2].join('::'))
7
- end
8
- alias extension_class lex_class
9
-
10
- def lex_name
11
- @lex_name ||= calling_class_array[2].gsub(/(?<!^)[A-Z]/) { "_#{$&}" }.downcase
12
- end
13
- alias extension_name lex_name
14
- alias lex_filename lex_name
15
-
16
- def lex_const
17
- @lex_const ||= calling_class_array[2]
18
- end
19
-
20
- def calling_class
21
- @calling_class ||= respond_to?(:ancestors) ? ancestors.first : self.class
22
- end
23
-
24
- def calling_class_array
25
- @calling_class_array ||= calling_class.to_s.split('::')
26
- end
27
-
28
- def actor_class
29
- calling_class
30
- end
31
-
32
- def actor_name
33
- @actor_name ||= calling_class_array.last.gsub(/(?<!^)[A-Z]/) { "_#{$&}" }.downcase
34
- end
35
-
36
- def actor_const
37
- @actor_const ||= calling_class_array.last
38
- end
39
-
40
- def runner_class
41
- @runner_class ||= Kernel.const_get(actor_class.to_s.sub!('Actor', 'Runners'))
42
- end
43
-
44
- def runner_name
45
- @runner_name ||= runner_class.to_s.split('::').last.gsub(/(?<!^)[A-Z]/) { "_#{$&}" }.downcase
46
- end
47
-
48
- def runner_const
49
- @runner_const ||= runner_class.to_s.split('::').last
50
- end
51
-
52
- def full_path
53
- @full_path ||= "#{Gem::Specification.find_by_name("lex-#{lex_name}").gem_dir}/lib/legion/extensions/#{lex_filename}"
54
- end
55
- alias extension_path full_path
56
-
57
- def from_json(string)
58
- Legion::JSON.load(string)
59
- end
60
-
61
- def normalize(thing)
62
- if thing.is_a? String
63
- to_json(from_json(thing))
64
- else
65
- from_json(to_json(thing))
66
- end
67
- end
68
-
69
- def to_dotted_hash(hash, recursive_key = '')
70
- hash.each_with_object({}) do |(k, v), ret|
71
- key = recursive_key + k.to_s
72
- if v.is_a? Hash
73
- ret.merge! to_dotted_hash(v, "#{key}.")
74
- else
75
- ret[key.to_sym] = v
76
- end
77
- end
78
- end
79
- end
80
- end
81
- end
82
- end
@@ -1,41 +0,0 @@
1
- require_relative 'base'
2
- module Legion
3
- module Extensions
4
- module Helpers
5
- module Core
6
- include Legion::Extensions::Helpers::Base
7
-
8
- def settings
9
- if Legion::Settings[:extensions].key?(lex_filename.to_sym)
10
- Legion::Settings[:extensions][lex_filename.to_sym]
11
- else
12
- { logger: { level: 'info', extended: false, internal: false } }
13
- end
14
- end
15
-
16
- # looks local, then in crypt, then settings, then cache, then env
17
- def find_setting(name, **opts)
18
- log.debug ".find_setting(#{name}) called"
19
- return opts[name.to_sym] if opts.key? name.to_sym
20
-
21
- string_name = "#{lex_name}_#{name.to_s.downcase}"
22
- if Legion::Settings[:crypt][:vault][:connected] && Legion::Crypt.exist?(lex_name)
23
- log.debug "looking for #{string_name} in Legion::Crypt"
24
- crypt_result = Legion::Crypt.get(lex_name)
25
- return crypt_result[name.to_sym] if crypt_result.is_a?(Hash) && crypt_result.key?(name.to_sym)
26
- end
27
- return settings[name.to_sym] if settings.key? name.to_sym
28
-
29
- if Legion::Settings[:cache][:connected]
30
- log.debug "looking for #{string_name} in Legion::Cache"
31
- cache_result = Legion::Cache.get(string_name)
32
- return cache_result unless cache_result.nil?
33
- end
34
-
35
- ENV[string_name] if ENV.key? string_name
36
- nil
37
- end
38
- end
39
- end
40
- end
41
- end
@@ -1,20 +0,0 @@
1
- module Legion
2
- module Extensions
3
- module Helpers
4
- module Lex
5
- include Legion::Extensions::Helpers::Core
6
- include Legion::Extensions::Helpers::Logger
7
-
8
- def self.included(base)
9
- base.send :extend, Legion::Extensions::Helpers::Core if base.class == Class
10
- base.send :extend, Legion::Extensions::Helpers::Logger if base.class == Class
11
- base.extend base if base.class == Module
12
- end
13
-
14
- def default_settings
15
- { logger: { level: 'info' } }
16
- end
17
- end
18
- end
19
- end
20
- end
@@ -1,47 +0,0 @@
1
- module Legion
2
- module Extensions
3
- module Helpers
4
- module Logger
5
- def log # rubocop:disable Metrics/AbcSize
6
- return @log unless @log.nil?
7
-
8
- logger_hash = { lex: lex_filename || nil }
9
- logger_hash[:lex] = lex_filename.first if logger_hash[:lex].is_a? Array
10
- if respond_to?(:settings) && settings.key?(:logger)
11
- logger_hash[:level] = settings[:logger][:level] if settings[:logger].key? :level
12
- logger_hash[:level] = settings[:logger][:log_file] if settings[:logger].key? :log_file
13
- logger_hash[:level] = 'info' unless settings[:logger].key? :log_file
14
- logger_hash[:trace] = settings[:logger][:trace] if settings[:logger].key? :trace
15
- logger_hash[:extended] = settings[:logger][:extended] if settings[:logger].key? :extended
16
- elsif respond_to?(:settings)
17
- Legion::Logging.warn Legion::Settings[:extensions][lex_filename.to_sym]
18
- Legion::Logging.warn "#{lex_name} has settings but no :logger key"
19
- else
20
- Legion::Logging.warn 'no settings'
21
- end
22
- @log = Legion::Logging::Logger.new(**logger_hash)
23
- end
24
-
25
- def handle_exception(exception, task_id: nil, **opts)
26
- log.error exception.message + " for task_id: #{task_id} but was logged "
27
- log.error exception.backtrace[0..10]
28
- log.error opts
29
-
30
- unless task_id.nil?
31
- Legion::Transport::Messages::TaskLog.new(
32
- task_id: task_id,
33
- runner_class: to_s,
34
- entry: {
35
- exception: true,
36
- message: exception.message,
37
- **opts
38
- }
39
- ).publish
40
- end
41
-
42
- raise Legion::Exception::HandledTask
43
- end
44
- end
45
- end
46
- end
47
- end
@@ -1,40 +0,0 @@
1
- require 'legion/transport'
2
- require 'legion/transport/messages/task_update'
3
- require 'legion/transport/messages/task_log'
4
-
5
- module Legion
6
- module Extensions
7
- module Helpers
8
- module Task
9
- def generate_task_log(task_id:, runner_class: to_s, function:, **payload)
10
- Legion::Transport::Messages::TaskLog.new(task_id: task_id, runner_class: runner_class, function: function, entry: payload).publish
11
- end
12
-
13
- def task_update(task_id, status, **opts)
14
- return if task_id.nil? || status.nil?
15
-
16
- update_hash = { task_id: task_id, status: status }
17
- %i[results payload function_args payload results].each do |column|
18
- update_hash[column] = opts[column] if opts.key? column
19
- end
20
- Legion::Transport::Messages::TaskUpdate.new(**update_hash).publish
21
- rescue StandardError => e
22
- log.fatal e.message
23
- log.fatal e.backtrace
24
- raise e
25
- end
26
-
27
- def generate_task_id(function_id:, status: 'task.queued', **opts)
28
- insert = { status: status, function_id: function_id }
29
- insert[:payload] = Legion::JSON.dump(opts[:payload]) if opts.key? :payload
30
- insert[:function_args] = Legion::JSON.dump(opts[:args]) if opts.key? :args
31
- %i[master_id parent_id relationship_id task_id].each do |column|
32
- insert[column] = opts[column] if opts.key? column
33
- end
34
-
35
- { success: true, task_id: Legion::Data::Model::Task.insert(insert), **insert }
36
- end
37
- end
38
- end
39
- end
40
- end