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,16 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- require 'bundler/setup'
5
- require 'legion'
6
- Legion::Service.new
7
-
8
- # You can add fixtures and/or initialization code here to make experimenting
9
- # with your gem easier. You can also use a different console, if you like.
10
-
11
- # (If you use this, don't forget to add pry to your Gemfile!)
12
- require 'pry'
13
- Pry.start
14
-
15
- require 'irb'
16
- IRB.start(__FILE__)
data/bin/legion DELETED
@@ -1,50 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- require 'optparse'
5
-
6
- options = { action: :run }
7
-
8
- daemonize_help = 'run daemonized in the background (default: false)'
9
- pidfile_help = 'the pid filename'
10
- logfile_help = 'the log filename'
11
- include_help = 'an additional $LOAD_PATH (may be used more than once)'
12
- debug_help = 'set $DEBUG to true'
13
- warn_help = 'enable warnings'
14
- time_help = 'only run legion for X seconds'
15
-
16
- op = OptionParser.new
17
- op.banner = 'An example of how to daemonize a long running Ruby process.'
18
- op.separator ''
19
- op.separator 'Usage: server [options]'
20
- op.separator ''
21
-
22
- op.separator ''
23
- op.separator 'Process options:'
24
- op.on('-d', '--daemonize', daemonize_help) { options[:daemonize] = true }
25
- op.on('-p', '--pid PIDFILE', pidfile_help) { |value| options[:pidfile] = value }
26
- op.on('-l', '--log LOGFILE', logfile_help) { |value| options[:logfile] = value }
27
- op.on('-t', '--time 10', time_help) { |value| options[:time_limit] = value }
28
-
29
- op.separator ''
30
- op.separator 'Ruby options:'
31
- op.on('-I', '--include PATH', include_help) do |value|
32
- $LOAD_PATH.unshift(*value.split(':').map do |v|
33
- File.expand_path(v)
34
- end)
35
- end
36
- op.on('--debug', debug_help) { $DEBUG = true }
37
- op.on('--warn', warn_help) { $-w = true }
38
-
39
- op.separator ''
40
- op.separator 'Common options:'
41
- op.on('-h', '--help') { options[:action] = :help }
42
- op.on('-v', '--version') { options[:action] = :version }
43
-
44
- op.separator ''
45
- op.parse!(ARGV)
46
-
47
- require File.expand_path('lib/legion.rb') unless options[:action] == :help
48
- Legion.start
49
- require File.expand_path('lib/legion/process.rb') unless options[:action] == :help
50
- Legion::Process.new(options).run!
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
data/bin/test DELETED
@@ -1,32 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
- # rubocop:disable all
4
- require 'cli-tree'
5
- # require File.expand_path('lib/legion.rb')
6
- # Legion.setup
7
- require 'legion/json'
8
- require 'legion/logging'
9
- require 'legion/settings'
10
- require 'legion/data'
11
- Legion::Logging.setup(level: 'debug')
12
- Legion::Settings.load
13
- Legion::Settings.merge_settings('data', Legion::Data::Settings.default)
14
- Legion::Data.setup
15
- extensions = {name: 'extensions', children: []}
16
- Legion::Data::Model::Extension.each do | extension|
17
- runners = []
18
- extension.runners.each do |runner|
19
- functions = []
20
- runner.functions.each do |function|
21
- functions.push function.values[:name]
22
- end
23
- # runners.push runner.values[:name]
24
- runners.push({name: runner.values[:name], children: functions})
25
- end
26
- child = {name: extension.values[:name], children: runners}
27
- # extensions[:children].push extension.values[:name]
28
- extensions[:children].push child
29
- end
30
-
31
- tree = TreeNode.from_h(extensions)
32
- tree.print
@@ -1,55 +0,0 @@
1
- image: ruby:2.5.0
2
-
3
- pipelines:
4
- tags:
5
- '0.1.0':
6
- - step:
7
- caches:
8
- - bundler
9
- deployment: rubygems
10
- script:
11
- - mkdir -p ~/.gem/credentials
12
- - (umask 077 ; echo $gem_creds | base64 --decode > ~/.gem/credentials)
13
- - gem build legion.gemspec
14
- - gem push legionio-*.gem
15
- branches:
16
- master:
17
- - step:
18
- caches:
19
- - bundler
20
- script:
21
- - gem install bundle rubocop
22
- - bundle install
23
- - rubocop
24
- - rake
25
- services:
26
- - mysql
27
- - broker
28
- default:
29
- - step:
30
- caches:
31
- - bundler
32
- script:
33
- - gem install bundle rubocop
34
- - bundle install
35
- - rubocop
36
- - rake
37
- services:
38
- - mysql
39
- - broker
40
- definitions:
41
- caches:
42
- bundler: vendor/bundle
43
- services:
44
- mysql:
45
- image: mysql:5.7
46
- environment:
47
- MYSQL_DATABASE: 'legion'
48
- MYSQL_ROOT_PASSWORD: 'legion'
49
- MYSQL_USER: 'legion'
50
- MYSQL_PASSWORD: 'legion'
51
- broker:
52
- image: rabbitmq:3
53
- environment:
54
- RABBITMQ_DEFAULT_USER: guest
55
- RABBITMQ_DEFAULT_PASS: guest
data/exe/legion DELETED
@@ -1,50 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- require 'optparse'
5
-
6
- options = { action: :run }
7
-
8
- daemonize_help = 'run daemonized in the background (default: false)'
9
- pidfile_help = 'the pid filename'
10
- logfile_help = 'the log filename'
11
- include_help = 'an additional $LOAD_PATH (may be used more than once)'
12
- debug_help = 'set $DEBUG to true'
13
- warn_help = 'enable warnings'
14
- time_help = 'only run legion for X seconds'
15
-
16
- op = OptionParser.new
17
- op.banner = 'An example of how to daemonize a long running Ruby process.'
18
- op.separator ''
19
- op.separator 'Usage: server [options]'
20
- op.separator ''
21
-
22
- op.separator ''
23
- op.separator 'Process options:'
24
- op.on('-d', '--daemonize', daemonize_help) { options[:daemonize] = true }
25
- op.on('-p', '--pid PIDFILE', pidfile_help) { |value| options[:pidfile] = value }
26
- op.on('-l', '--log LOGFILE', logfile_help) { |value| options[:logfile] = value }
27
- op.on('-t', '--time 10', time_help) { |value| options[:time_limit] = value }
28
-
29
- op.separator ''
30
- op.separator 'Ruby options:'
31
- op.on('-I', '--include PATH', include_help) do |value|
32
- $LOAD_PATH.unshift(*value.split(':').map do |v|
33
- File.expand_path(v)
34
- end)
35
- end
36
- op.on('--debug', debug_help) { $DEBUG = true }
37
- op.on('--warn', warn_help) { $-w = true }
38
-
39
- op.separator ''
40
- op.separator 'Common options:'
41
- op.on('-h', '--help') { options[:action] = :help }
42
- op.on('-v', '--version') { options[:action] = :version }
43
-
44
- op.separator ''
45
- op.parse!(ARGV)
46
-
47
- require File.expand_path('lib/legion.rb') unless options[:action] == :help
48
- Legion.start
49
- require File.expand_path('lib/legion/process.rb') unless options[:action] == :help
50
- Legion::Process.new(options).run!
@@ -1,59 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- lib = File.expand_path('lib', __dir__)
4
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require 'legion/version'
6
-
7
- Gem::Specification.new do |spec|
8
- spec.name = (RUBY_ENGINE == 'jruby' ? 'legionio-java' : 'legionio')
9
- spec.version = Legion::VERSION
10
- spec.authors = ['Esity']
11
- spec.email = ['matthewdiverson@gmail.com']
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.license = 'MIT'
17
- spec.required_ruby_version = '>= 2.5.0'
18
-
19
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
20
- f.match(%r{^(test|spec|features)/})
21
- end
22
- spec.bindir = 'exe'
23
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
- spec.require_paths = ['lib']
25
-
26
- if RUBY_ENGINE == 'jruby'
27
- spec.add_dependency 'jrjackson'
28
- spec.add_dependency 'legion-data-java'
29
- spec.add_dependency 'legion-transport-java'
30
- spec.add_dependency 'march_hare'
31
- else
32
- spec.add_dependency 'concurrent-ruby-ext'
33
- spec.add_dependency 'legion-data'
34
- spec.add_dependency 'legion-transport'
35
- spec.add_dependency 'oj'
36
- end
37
-
38
- spec.add_dependency 'concurrent-ruby'
39
- spec.add_dependency 'daemons'
40
- spec.add_dependency 'hashdiff'
41
-
42
- spec.add_dependency 'bunny'
43
- spec.add_dependency 'legion-cache'
44
- spec.add_dependency 'legion-crypt'
45
- spec.add_dependency 'legion-exceptions'
46
- spec.add_dependency 'legion-json'
47
- spec.add_dependency 'legion-logging'
48
- spec.add_dependency 'legion-settings'
49
-
50
- spec.add_dependency 'lex-node'
51
-
52
- spec.add_development_dependency 'bundler'
53
- spec.add_development_dependency 'codecov'
54
- spec.add_development_dependency 'rake'
55
- spec.add_development_dependency 'rspec'
56
- spec.add_development_dependency 'rspec_junit_formatter'
57
- spec.add_development_dependency 'rubocop'
58
- spec.add_development_dependency 'simplecov'
59
- end
@@ -1,21 +0,0 @@
1
- Process.setproctitle('Legion')
2
- require 'concurrent'
3
- require 'securerandom'
4
- require 'legion/exceptions'
5
- require 'legion/version'
6
- require 'legion/process'
7
- require 'legion/service'
8
- require 'legion/extensions'
9
-
10
- module Legion
11
- attr_reader :service
12
-
13
- def self.start
14
- @service = Legion::Service.new
15
- Legion::Logging.info("Started Legion v#{Legion::VERSION}")
16
- end
17
-
18
- def self.shutdown
19
- @service.shutdown
20
- end
21
- end
@@ -1,6 +0,0 @@
1
- module Legion
2
- module Exception
3
- class HandledTask < StandardError
4
- end
5
- end
6
- end
@@ -1,5 +0,0 @@
1
- module Legion
2
- module Exception
3
- class InvalidJson < StandardError; end
4
- end
5
- end
@@ -1,6 +0,0 @@
1
- module Legion
2
- module Exception
3
- class MissingArgument < StandardError
4
- end
5
- end
6
- end
@@ -1,10 +0,0 @@
1
- require_relative 'wrongtypes/array'
2
- require_relative 'wrongtypes/hash'
3
- require_relative 'wrongtypes/integer'
4
- require_relative 'wrongtypes/string'
5
-
6
- module Legion
7
- module Exception
8
- class WrongType < StandardError; end
9
- end
10
- end
@@ -1,8 +0,0 @@
1
- module Legion
2
- module Exception
3
- module WrongType
4
- class Array < TypeError
5
- end
6
- end
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- module Legion
2
- module Exception
3
- module WrongType
4
- class Hash < TypeError
5
- end
6
- end
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- module Legion
2
- module Exception
3
- module WrongType
4
- class Integer < TypeError
5
- end
6
- end
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- module Legion
2
- module Exception
3
- module WrongType
4
- class String < TypeError
5
- end
6
- end
7
- end
8
- end
@@ -1,164 +0,0 @@
1
- require 'legion/extensions/core'
2
- require 'legion/runner'
3
-
4
- module Legion
5
- module Extensions
6
- class << self
7
- def setup
8
- hook_extensions
9
- end
10
-
11
- def hook_extensions
12
- @timer_tasks = []
13
- @loop_tasks = []
14
- @once_tasks = []
15
- @poll_tasks = []
16
- @subscription_tasks = []
17
- @actors = []
18
-
19
- find_extensions
20
- load_extensions
21
- end
22
-
23
- def shutdown
24
- return nil if @loaded_extensions.nil?
25
-
26
- @subscription_tasks.each do |task|
27
- task[:threadpool].shutdown
28
- task[:threadpool].kill unless task[:threadpool].wait_for_termination(5)
29
- end
30
-
31
- @loop_tasks.each { |task| task[:running_class].cancel if task[:running_class].respond_to?(:cancel) }
32
- @once_tasks.each { |task| task[:running_class].cancel if task[:running_class].respond_to?(:cancel) }
33
- @timer_tasks.each { |task| task[:running_class].cancel if task[:running_class].respond_to?(:cancel) }
34
- @poll_tasks.each { |task| task[:running_class].cancel if task[:running_class].respond_to?(:cancel) }
35
-
36
- Legion::Logging.info 'Successfully shut down all actors'
37
- end
38
-
39
- def load_extensions
40
- @extensions ||= {}
41
- @loaded_extensions ||= []
42
- @extensions.each do |extension, values|
43
- if values.key(:enabled) && !values[:enabled]
44
- Legion::Logging.info "Skipping #{extension} because it's disabled"
45
- next
46
- end
47
-
48
- if Legion::Settings[:extensions].key?(extension.to_sym) && Legion::Settings[:extensions][extension.to_sym].key?(:enabled) && !Legion::Settings[:extensions][extension.to_sym][:enabled] # rubocop:disable Layout/LineLength
49
- next
50
- end
51
-
52
- unless load_extension(extension, values)
53
- Legion::Logging.warn("#{extension} failed to load")
54
- next
55
- end
56
- @loaded_extensions.push(extension)
57
- end
58
- 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}"
59
- end
60
-
61
- def load_extension(extension, values)
62
- return unless gem_load(values[:gem_name], extension)
63
-
64
- extension = Kernel.const_get(values[:extension_class])
65
- has_logger = extension.respond_to?(:log)
66
- extension.autobuild
67
-
68
- require 'legion/transport/messages/lex_register'
69
- Legion::Transport::Messages::LexRegister.new(function: 'save', opts: extension.runners).publish
70
-
71
- if extension.respond_to?(:meta_actors) && extension.meta_actors.is_a?(Array)
72
- extension.meta_actors.each do |_key, actor|
73
- extension.log.debug("hooking meta actor: #{actor}") if has_logger
74
- hook_actor(**actor)
75
- end
76
- end
77
-
78
- extension.actors.each do |_key, actor|
79
- extension.log.debug("hooking literal actor: #{actor}") if has_logger
80
- hook_actor(**actor)
81
- end
82
- extension.log.info "Loaded v#{extension::VERSION}"
83
- rescue StandardError => e
84
- Legion::Logging.error e.message
85
- Legion::Logging.error e.backtrace
86
- false
87
- end
88
-
89
- def hook_actor(extension:, extension_name:, actor_class:, size: 1, **opts)
90
- size = if Legion::Settings[:extensions].key?(extension_name.to_sym) && Legion::Settings[:extensions][extension_name.to_sym].key?(:workers)
91
- Legion::Settings[:extensions][extension_name.to_sym][:workers]
92
- elsif size.is_a? Integer
93
- size
94
- else
95
- 1
96
- end
97
-
98
- extension_hash = {
99
- extension: extension,
100
- extension_name: extension_name,
101
- actor_class: actor_class,
102
- size: size,
103
- fallback_policy: :abort,
104
- **opts
105
- }
106
- extension_hash[:running_class] = if actor_class.ancestors.include? Legion::Extensions::Actors::Subscription
107
- actor_class
108
- else
109
- actor_class.new
110
- end
111
-
112
- if actor_class.ancestors.include? Legion::Extensions::Actors::Every
113
- @timer_tasks.push(extension_hash)
114
- elsif actor_class.ancestors.include? Legion::Extensions::Actors::Once
115
- @once_tasks.push(extension_hash)
116
- elsif actor_class.ancestors.include? Legion::Extensions::Actors::Loop
117
- @loop_tasks.push(extension_hash)
118
- elsif actor_class.ancestors.include? Legion::Extensions::Actors::Poll
119
- @poll_tasks.push(extension_hash)
120
- elsif actor_class.ancestors.include? Legion::Extensions::Actors::Subscription
121
- extension_hash[:threadpool] = Concurrent::FixedThreadPool.new(size)
122
- size.times do
123
- extension_hash[:threadpool].post do
124
- klass = actor_class.new
125
- if klass.respond_to?(:async)
126
- klass.async.subscribe
127
- else
128
- klass.subscribe
129
- end
130
- end
131
- end
132
- @subscription_tasks.push(extension_hash)
133
- else
134
- Legion::Logging.fatal 'did not match any actor classes'
135
- end
136
- end
137
-
138
- def gem_load(gem_name, name)
139
- gem_path = "#{Gem::Specification.find_by_name(gem_name).gem_dir}/lib/legion/extensions/#{name}"
140
- require gem_path
141
- true
142
- rescue LoadError => e
143
- Legion::Logging.error e.message
144
- Legion::Logging.error e.backtrace
145
- Legion::Logging.error "gem_path: #{gem_path}" unless gem_path.nil?
146
- false
147
- end
148
-
149
- def find_extensions
150
- @extensions ||= {}
151
- Gem::Specification.all_names.each do |gem|
152
- next unless gem[0..3] == 'lex-'
153
-
154
- lex = gem.split('-')
155
- @extensions[lex[1]] = { full_gem_name: gem,
156
- gem_name: "lex-#{lex[1]}",
157
- extension_name: lex[1],
158
- version: lex[2],
159
- extension_class: "Legion::Extensions::#{lex[1].capitalize}" }
160
- end
161
- end
162
- end
163
- end
164
- end