legionio 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +27 -10
  3. data/.gitignore +1 -0
  4. data/.rubocop.yml +7 -2
  5. data/CHANGELOG.md +21 -0
  6. data/Dockerfile +9 -0
  7. data/Gemfile +0 -11
  8. data/README.md +158 -42
  9. data/Rakefile +0 -6
  10. data/bitbucket-pipelines.yml +17 -52
  11. data/docker_deploy.rb +8 -0
  12. data/exe/legion +3 -49
  13. data/{bin/legion → exe/legionio} +5 -42
  14. data/exe/lex_gen +5 -0
  15. data/{legion.gemspec → legionio.gemspec} +25 -20
  16. data/lib/legion.rb +4 -0
  17. data/lib/legion/cli.rb +56 -0
  18. data/lib/legion/cli/chain.rb +35 -0
  19. data/lib/legion/cli/cohort.rb +10 -0
  20. data/lib/legion/cli/function.rb +41 -0
  21. data/lib/legion/cli/lex/actor.rb +31 -0
  22. data/lib/legion/cli/lex/exchange.rb +32 -0
  23. data/lib/legion/cli/lex/message.rb +32 -0
  24. data/lib/legion/cli/lex/queue.rb +45 -0
  25. data/lib/legion/cli/lex/runner.rb +70 -0
  26. data/lib/legion/cli/lex/templates/actor.erb +6 -0
  27. data/lib/legion/cli/lex/templates/actor_spec.erb +0 -0
  28. data/lib/legion/cli/lex/templates/base/bitbucket.yml.erb +69 -0
  29. data/lib/legion/cli/lex/templates/base/gemfile.erb +3 -0
  30. data/lib/legion/cli/lex/templates/base/gemspec.erb +26 -0
  31. data/lib/legion/cli/lex/templates/base/gitignore.erb +11 -0
  32. data/lib/legion/cli/lex/templates/base/lex.erb +9 -0
  33. data/lib/legion/cli/lex/templates/base/lex_spec.erb +5 -0
  34. data/lib/legion/cli/lex/templates/base/lic.erb +21 -0
  35. data/lib/legion/cli/lex/templates/base/rakefile.erb +6 -0
  36. data/lib/legion/cli/lex/templates/base/readme.md.erb +2 -0
  37. data/lib/legion/cli/lex/templates/base/rubocop.yml.erb +15 -0
  38. data/lib/legion/cli/lex/templates/base/spec_helper.rb.erb +11 -0
  39. data/lib/legion/cli/lex/templates/base/version.erb +7 -0
  40. data/lib/legion/cli/lex/templates/exchange.erb +11 -0
  41. data/lib/legion/cli/lex/templates/exchange_spec.erb +0 -0
  42. data/lib/legion/cli/lex/templates/message.erb +23 -0
  43. data/lib/legion/cli/lex/templates/message_spec.erb +0 -0
  44. data/lib/legion/cli/lex/templates/queue.erb +12 -0
  45. data/lib/legion/cli/lex/templates/queue_helper.erb +24 -0
  46. data/lib/legion/cli/lex/templates/queue_spec.erb +11 -0
  47. data/lib/legion/cli/lex/templates/runner.erb +11 -0
  48. data/lib/legion/cli/lex/templates/runner_spec.erb +11 -0
  49. data/lib/legion/cli/relationship.rb +22 -0
  50. data/lib/legion/cli/task.rb +49 -0
  51. data/lib/legion/cli/trigger.rb +88 -0
  52. data/lib/legion/cli/version.rb +5 -0
  53. data/lib/legion/extensions.rb +57 -62
  54. data/lib/legion/extensions/actors/base.rb +0 -2
  55. data/lib/legion/extensions/actors/poll.rb +0 -1
  56. data/lib/legion/extensions/actors/subscription.rb +1 -0
  57. data/lib/legion/extensions/builders/runners.rb +5 -0
  58. data/lib/legion/extensions/core.rb +9 -4
  59. data/lib/legion/extensions/helpers/base.rb +3 -3
  60. data/lib/legion/extensions/helpers/lex.rb +29 -1
  61. data/lib/legion/extensions/helpers/logger.rb +3 -6
  62. data/lib/legion/extensions/helpers/task.rb +1 -1
  63. data/lib/legion/extensions/transport.rb +9 -7
  64. data/lib/legion/lex.rb +89 -0
  65. data/lib/legion/service.rb +55 -4
  66. data/lib/legion/version.rb +1 -1
  67. metadata +196 -51
  68. data/bin/console +0 -16
  69. data/bin/setup +0 -8
  70. data/bin/test +0 -32
  71. data/lib/legion/exceptions/handled_task.rb +0 -6
  72. data/lib/legion/exceptions/invalidjson.rb +0 -5
  73. data/lib/legion/exceptions/missingargument.rb +0 -6
  74. data/lib/legion/exceptions/wrongtype.rb +0 -10
  75. data/lib/legion/exceptions/wrongtypes/array.rb +0 -8
  76. data/lib/legion/exceptions/wrongtypes/hash.rb +0 -8
  77. data/lib/legion/exceptions/wrongtypes/integer.rb +0 -8
  78. data/lib/legion/exceptions/wrongtypes/string.rb +0 -8
  79. data/settings/client.json +0 -25
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require './lib/legion/version'
4
+ puts "Building docker image for Legion v#{Legion::VERSION}"
5
+ system("docker build --tag legionio/legion:v#{Legion::VERSION} .")
6
+ puts 'Pushing to hub.docker.com'
7
+ system("docker push legionio/legion:v#{Legion::VERSION}")
8
+ puts 'completed'
data/exe/legion CHANGED
@@ -1,50 +1,4 @@
1
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!
2
+ require 'thor'
3
+ require 'legion/cli'
4
+ Legion::CLI.start
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'optparse'
5
- require 'etc'
4
+ $LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
6
5
 
6
+ require 'optparse'
7
7
  options = { action: :run }
8
8
 
9
9
  daemonize_help = 'run daemonized in the background (default: false)'
@@ -45,46 +45,9 @@ op.on('-v', '--version') { options[:action] = :version }
45
45
  op.separator ''
46
46
  op.parse!(ARGV)
47
47
 
48
- @children = []
49
- children = 5
50
- if children == 1
51
- require File.expand_path('lib/legion.rb') unless options[:action] == :help
52
- require File.expand_path('lib/legion/process.rb') unless options[:action] == :help
48
+ unless options[:action] == :help
49
+ require 'legion'
53
50
  Legion.start
51
+ require 'legion/process'
54
52
  Legion::Process.new(options).run!
55
- else
56
- children.times do
57
- @children.push(
58
- Process.fork do
59
- require File.expand_path('lib/legion.rb') unless options[:action] == :help
60
- require File.expand_path('lib/legion/process.rb') unless options[:action] == :help
61
-
62
- Legion.start
63
- sleep(1)
64
- Legion::Process.new(options).run!
65
- end
66
- )
67
- sleep(5)
68
- end
69
-
70
- @quit = false
71
- trap('SIGINT') do
72
- @quit = true
73
- @children.each do |child|
74
- Process.kill('SIGINT', child)
75
- end
76
- sleep(5)
77
- end
78
-
79
- trap('SIGTERM') do
80
- @children.each do |child|
81
- Process.kill('SIGTERM', child)
82
- end
83
-
84
- sleep(5)
85
- end
86
-
87
- sleep(1) until @quit
88
53
  end
89
-
90
- sleep(2)
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ require 'thor'
3
+ require 'legion/lex'
4
+
5
+ Legion::Cli::LexBuilder.start
@@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
  require 'legion/version'
6
6
 
7
7
  Gem::Specification.new do |spec|
8
- spec.name = (RUBY_ENGINE == 'jruby' ? 'legionio-java' : 'legionio')
8
+ spec.name = 'legionio'
9
9
  spec.version = Legion::VERSION
10
10
  spec.authors = ['Esity']
11
11
  spec.email = ['matthewdiverson@gmail.com']
@@ -13,47 +13,52 @@ Gem::Specification.new do |spec|
13
13
  spec.summary = 'Legion Core Software to string it all together'
14
14
  spec.description = 'Legion Core runs Legion Framwork'
15
15
  spec.homepage = 'https://bitbucket.org/legion-io/legion/'
16
- spec.license = 'MIT'
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'
17
20
  spec.required_ruby_version = '>= 2.5.0'
18
21
 
19
22
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
20
23
  f.match(%r{^(test|spec|features)/})
21
24
  end
25
+
22
26
  spec.bindir = 'exe'
23
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
28
  spec.require_paths = ['lib']
25
29
 
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'
30
+ spec.add_dependency 'concurrent-ruby', '>= 1.1.7'
31
+ spec.add_dependency 'concurrent-ruby-ext', '>= 1.1.7'
32
+ spec.add_dependency 'daemons', '>= 1.3.1'
33
+ spec.add_dependency 'oj', '>= 3.10'
34
+ spec.add_dependency 'thor', '>= 1'
41
35
 
42
- spec.add_dependency 'bunny'
43
36
  spec.add_dependency 'legion-cache'
44
- spec.add_dependency 'legion-crypt'
37
+ spec.add_dependency 'legion-crypt', '>= 0.2.0'
45
38
  spec.add_dependency 'legion-exceptions'
46
39
  spec.add_dependency 'legion-json'
47
40
  spec.add_dependency 'legion-logging'
48
41
  spec.add_dependency 'legion-settings'
42
+ spec.add_dependency 'legion-transport', '>= 1.1.8'
49
43
 
50
44
  spec.add_dependency 'lex-node'
51
45
 
52
- spec.add_development_dependency 'bundler'
53
46
  spec.add_development_dependency 'codecov'
47
+ spec.add_development_dependency 'legion-data'
54
48
  spec.add_development_dependency 'rake'
55
49
  spec.add_development_dependency 'rspec'
56
50
  spec.add_development_dependency 'rspec_junit_formatter'
57
51
  spec.add_development_dependency 'rubocop'
52
+ spec.add_development_dependency 'rubocop-rake'
53
+ spec.add_development_dependency 'rubocop-rspec'
58
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'
59
64
  end
@@ -18,4 +18,8 @@ module Legion
18
18
  def self.shutdown
19
19
  @service.shutdown
20
20
  end
21
+
22
+ def self.reload
23
+ @service.reload
24
+ end
21
25
  end
@@ -0,0 +1,56 @@
1
+ # require 'legion/cli/version'
2
+ require 'thor'
3
+ require 'legion'
4
+ require 'legion/service'
5
+
6
+ require 'legion/lex'
7
+ require 'legion/cli/cohort'
8
+
9
+ require 'legion/cli/relationship'
10
+ require 'legion/cli/task'
11
+ require 'legion/cli/chain'
12
+ require 'legion/cli/trigger'
13
+ require 'legion/cli/function'
14
+
15
+ module Legion
16
+ class CLI < Thor
17
+ include Thor::Actions
18
+ check_unknown_options!
19
+
20
+ def self.exit_on_failure?
21
+ true
22
+ end
23
+
24
+ def self.source_root
25
+ File.dirname(__FILE__)
26
+ end
27
+
28
+ desc 'version', 'Display MyGem version'
29
+ map %w[-v --version] => :version
30
+
31
+ def version
32
+ say "Legion::CLI #{VERSION}"
33
+ end
34
+
35
+ desc 'lex', 'used to build LEXs'
36
+ subcommand 'lex', Legion::Cli::LexBuilder
37
+
38
+ desc 'cohort', ''
39
+ subcommand 'cohort', Legion::Cli::Cohort
40
+
41
+ desc 'function', 'deal with functions'
42
+ subcommand 'function', Legion::Cli::Function
43
+
44
+ desc 'relationship', 'creates and manages relationships'
45
+ subcommand 'relationship', Legion::Cli::Relationship
46
+
47
+ desc 'task', 'creates and manages tasks'
48
+ subcommand 'task', Legion::Cli::Task
49
+
50
+ desc 'chain', 'creates and manages chains'
51
+ subcommand 'chain', Legion::Cli::Chain
52
+
53
+ desc 'trigger', 'sends a task to a worker'
54
+ subcommand 'trigger', Legion::Cli::Trigger
55
+ end
56
+ end
@@ -0,0 +1,35 @@
1
+ module Legion
2
+ class Cli
3
+ class Chain < Thor
4
+ desc 'create', 'create'
5
+ def create(name)
6
+ Legion::Service.new(cache: false, crypt: false, extensions: false, log_level: 'error')
7
+ say "chain created, id: #{Legion::Data::Model::Chain.insert({ name: name })}", :green
8
+ end
9
+
10
+ desc 'show', 'show'
11
+ option :limit, type: :numeric, required: true, default: 10, desc: 'how many tasks to return'
12
+ def show
13
+ Legion::Service.new(cache: false, crypt: false, extensions: false, log_level: 'error')
14
+ rows = [%w[id name active]]
15
+ Legion::Data::Model::Chain.limit(options[:limit]).order(:id).reverse_each do |row|
16
+ rows.push([row.values[:id], row.values[:name], row.values[:active]])
17
+ end
18
+
19
+ print_table rows
20
+ end
21
+
22
+ desc 'delete', 'delete'
23
+ option :confirm, type: :boolean
24
+ def delete(id)
25
+ Legion::Service.new(cache: false, crypt: false, extensions: false, log_level: 'error')
26
+ return if !options[:confirm] && !(yes? "Are you sure you want to delete chain #{id} and all dependent relationships", :red)
27
+
28
+ Legion::Data::Model::Chain[id].delete
29
+ say 'Deleted!'
30
+ end
31
+
32
+ default_task :show
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,10 @@
1
+ module Legion
2
+ class Cli
3
+ class Cohort < Thor
4
+ desc 'import :id', 'imports a cohort for usage'
5
+ def import(id)
6
+ say "Importing Cohort #{id}", :green
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,41 @@
1
+ module Legion
2
+ class Cli
3
+ class Function < Thor
4
+ desc 'find', 'find'
5
+ option :internal, type: :boolean, default: false
6
+ def find
7
+ Legion::Service.new(cache: false, crypt: false, extensions: false, log_level: 'error')
8
+ response = ask 'trigger extension?', limited_to: Legion::Data::Model::Extension.map(:name)
9
+ trigger_extension = Legion::Data::Model::Extension.where(name: response).first
10
+ runners = Legion::Data::Model::Runner.where(extension_id: trigger_extension.values[:id])
11
+ if runners.count == 1
12
+ trigger_runner = runners.first
13
+ say "Auto selecting #{trigger_runner.values[:name]} since it is the only option"
14
+ else
15
+ response = ask 'trigger runner?', limited_to: runners.map(:name)
16
+ trigger_runner = Legion::Data::Model::Runner.where(name: response).where(extension_id: trigger_extension.values[:id]).first
17
+ end
18
+
19
+ functions = Legion::Data::Model::Function.where(runner_id: trigger_runner.values[:id])
20
+
21
+ if functions.count == 1
22
+ trigger_function = functions.first
23
+ say "Auto selecting #{trigger_function.values[:name]} since it is the only option"
24
+ else
25
+ response = ask 'trigger function?', limited_to: Legion::Data::Model::Function.where(runner_id: trigger_runner.values[:id]).map(:name)
26
+ trigger_function = trigger_runner.functions(name: response).first
27
+ end
28
+ # say "#{trigger_runner.values[:namespace]}.#{trigger_function.values[:name]} selected as trigger", :green, :italicized
29
+ # mute { trigger_function.values[:id] }
30
+ say trigger_function.values[:id]
31
+ # puts self.methods(false)
32
+ end
33
+
34
+ desc 'delete', 'delete'
35
+ def delete; end
36
+
37
+ desc 'activate', 'activate'
38
+ def activate; end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,31 @@
1
+ module Legion
2
+ class Cli
3
+ module Lex
4
+ class Actor < Thor
5
+ include Thor::Actions
6
+
7
+ def self.source_root
8
+ File.dirname(__FILE__)
9
+ end
10
+
11
+ no_commands do
12
+ def lex
13
+ Dir.pwd.split('/').last.split('-').last
14
+ end
15
+ end
16
+
17
+ desc 'create :name', 'creates a new actor'
18
+ method_option :type, enum: %w[subscription every poll once loop], default: 'subscription'
19
+ def create(name)
20
+ template('templates/actor.erb', "#{lex}/lib/actors/#{name}.rb", { name: name, lex: lex, type: options[:type] })
21
+ end
22
+
23
+ desc 'delete :name', 'deletes an actor'
24
+ def delete(name)
25
+ remove_file("lib/legion/extensions/#{lex}/actors/#{name}.rb")
26
+ remove_file("spec/actors/#{name}_spec.rb")
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,32 @@
1
+ module Legion
2
+ class Cli
3
+ module Lex
4
+ class Exchange < Thor
5
+ include Thor::Actions
6
+
7
+ def self.source_root
8
+ File.dirname(__FILE__)
9
+ end
10
+
11
+ no_commands do
12
+ def lex
13
+ Dir.pwd.split('/').last.split('-').last
14
+ end
15
+ end
16
+
17
+ desc 'create :name', 'creates a new exchange class'
18
+ def create(name)
19
+ template('templates/queue.erb', "lib/legion/extensions/#{lex}/transport/exchanges/#{name}.rb", { name: name, lex: lex })
20
+ template('templates/queue_spec.erb', "spec/exchanges/#{name}_spec.rb", { name: name, lex: lex })
21
+ end
22
+
23
+ desc 'delete :name', 'deletes an exchange class'
24
+ def delete(name)
25
+ remove_file("lib/legion/extensions/#{lex}/transport/exchanges/#{name}.rb")
26
+ remove_file("spec/exchanges/#{name}_spec.rb")
27
+ remove_file("spec/transport/exchanges/#{name}_spec.rb")
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,32 @@
1
+ module Legion
2
+ class Cli
3
+ module Lex
4
+ class Message < Thor
5
+ include Thor::Actions
6
+
7
+ def self.source_root
8
+ File.dirname(__FILE__)
9
+ end
10
+
11
+ no_commands do
12
+ def lex
13
+ Dir.pwd.split('/').last.split('-').last
14
+ end
15
+ end
16
+
17
+ desc 'create :name', 'creates a new message'
18
+ def create(name)
19
+ template('templates/message.erb', "lib/legion/extensions/#{lex}/transport/messages/#{name}.rb", { name: name, lex: lex })
20
+ template('templates/message_spec.erb', "spec/messages/#{name}_spec.rb", { name: name, lex: lex })
21
+ end
22
+
23
+ desc 'delete :name', 'deletes a message class'
24
+ def delete(name)
25
+ remove_file("lib/legion/extensions/#{lex}/transport/messages/#{name}.rb")
26
+ remove_file("spec/messages/#{name}_spec.rb")
27
+ remove_file("spec/transport/messages/#{name}_spec.rb")
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end