legionio 0.3.5 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +136 -0
- data/.gitignore +15 -0
- data/.rspec +2 -0
- data/.rubocop.yml +94 -0
- data/CHANGELOG.md +37 -0
- data/Dockerfile +9 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +21 -0
- data/README.md +162 -0
- data/Rakefile +32 -0
- data/bitbucket-pipelines.yml +20 -0
- data/docker_deploy.rb +8 -0
- data/exe/legion +4 -0
- data/exe/legionio +53 -0
- data/exe/lex_gen +5 -0
- data/legionio.gemspec +64 -0
- data/lib/legion.rb +25 -0
- data/lib/legion/cli.rb +56 -0
- data/lib/legion/cli/chain.rb +35 -0
- data/lib/legion/cli/cohort.rb +10 -0
- data/lib/legion/cli/function.rb +41 -0
- data/lib/legion/cli/lex/actor.rb +31 -0
- data/lib/legion/cli/lex/exchange.rb +32 -0
- data/lib/legion/cli/lex/message.rb +32 -0
- data/lib/legion/cli/lex/queue.rb +45 -0
- data/lib/legion/cli/lex/runner.rb +70 -0
- data/lib/legion/cli/lex/templates/actor.erb +6 -0
- data/lib/legion/cli/lex/templates/actor_spec.erb +0 -0
- data/lib/legion/cli/lex/templates/base/bitbucket.yml.erb +69 -0
- data/lib/legion/cli/lex/templates/base/gemfile.erb +3 -0
- data/lib/legion/cli/lex/templates/base/gemspec.erb +26 -0
- data/lib/legion/cli/lex/templates/base/gitignore.erb +11 -0
- data/lib/legion/cli/lex/templates/base/lex.erb +9 -0
- data/lib/legion/cli/lex/templates/base/lex_spec.erb +5 -0
- data/lib/legion/cli/lex/templates/base/lic.erb +21 -0
- data/lib/legion/cli/lex/templates/base/rakefile.erb +6 -0
- data/lib/legion/cli/lex/templates/base/readme.md.erb +2 -0
- data/lib/legion/cli/lex/templates/base/rubocop.yml.erb +15 -0
- data/lib/legion/cli/lex/templates/base/spec_helper.rb.erb +11 -0
- data/lib/legion/cli/lex/templates/base/version.erb +7 -0
- data/lib/legion/cli/lex/templates/exchange.erb +11 -0
- data/lib/legion/cli/lex/templates/exchange_spec.erb +0 -0
- data/lib/legion/cli/lex/templates/message.erb +23 -0
- data/lib/legion/cli/lex/templates/message_spec.erb +0 -0
- data/lib/legion/cli/lex/templates/queue.erb +12 -0
- data/lib/legion/cli/lex/templates/queue_helper.erb +24 -0
- data/lib/legion/cli/lex/templates/queue_spec.erb +11 -0
- data/lib/legion/cli/lex/templates/runner.erb +11 -0
- data/lib/legion/cli/lex/templates/runner_spec.erb +11 -0
- data/lib/legion/cli/relationship.rb +22 -0
- data/lib/legion/cli/task.rb +49 -0
- data/lib/legion/cli/trigger.rb +88 -0
- data/lib/legion/cli/version.rb +5 -0
- data/lib/legion/extensions.rb +219 -0
- data/lib/legion/extensions/actors/base.rb +47 -0
- data/lib/legion/extensions/actors/every.rb +48 -0
- data/lib/legion/extensions/actors/loop.rb +32 -0
- data/lib/legion/extensions/actors/nothing.rb +15 -0
- data/lib/legion/extensions/actors/once.rb +40 -0
- data/lib/legion/extensions/actors/poll.rb +87 -0
- data/lib/legion/extensions/actors/subscription.rb +139 -0
- data/lib/legion/extensions/builders/actors.rb +61 -0
- data/lib/legion/extensions/builders/base.rb +36 -0
- data/lib/legion/extensions/builders/helpers.rb +24 -0
- data/lib/legion/extensions/builders/runners.rb +58 -0
- data/lib/legion/extensions/core.rb +131 -0
- data/lib/legion/extensions/data.rb +58 -0
- data/lib/legion/extensions/data/migrator.rb +28 -0
- data/lib/legion/extensions/data/model.rb +8 -0
- data/lib/legion/extensions/helpers/base.rb +82 -0
- data/lib/legion/extensions/helpers/cache.rb +23 -0
- data/lib/legion/extensions/helpers/core.rb +41 -0
- data/lib/legion/extensions/helpers/data.rb +23 -0
- data/lib/legion/extensions/helpers/lex.rb +48 -0
- data/lib/legion/extensions/helpers/logger.rb +44 -0
- data/lib/legion/extensions/helpers/task.rb +60 -0
- data/lib/legion/extensions/helpers/transport.rb +44 -0
- data/lib/legion/extensions/transport.rb +159 -0
- data/lib/legion/lex.rb +89 -0
- data/lib/legion/process.rb +124 -0
- data/lib/legion/runner.rb +55 -0
- data/lib/legion/runner/log.rb +10 -0
- data/lib/legion/runner/status.rb +69 -0
- data/lib/legion/service.rb +130 -0
- data/lib/legion/supervision.rb +15 -0
- data/lib/legion/version.rb +3 -0
- metadata +239 -38
@@ -0,0 +1,45 @@
|
|
1
|
+
module Legion
|
2
|
+
class Cli
|
3
|
+
module Lex
|
4
|
+
class Queue < 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 queue'
|
18
|
+
def create(name)
|
19
|
+
template('templates/queue_helper.erb', 'spec/queue_helper.rb')
|
20
|
+
template('templates/queue.erb',
|
21
|
+
"lib/legion/extensions/#{lex}/transport/queues/#{name}.rb",
|
22
|
+
{ name: name, lex: lex })
|
23
|
+
template('templates/queue_spec.erb', "spec/queues/#{name}_spec.rb", { name: name, lex: lex })
|
24
|
+
end
|
25
|
+
|
26
|
+
desc 'delete :name', 'deletes a queue config file'
|
27
|
+
def delete(name)
|
28
|
+
remove_file("lib/legion/extensions/#{lex}/transport/queues/#{name}.rb")
|
29
|
+
remove_file("spec/queues/#{name}_spec.rb")
|
30
|
+
remove_file("spec/transport/queues/#{name}_spec.rb")
|
31
|
+
|
32
|
+
# puts Dir.pwd # /Users/miverso2/Rubymine/lex/wip/lex-conflux
|
33
|
+
if Dir.exist? "#{Dir.pwd}/lib/legion/extensions/#{lex}/transport/queues/"
|
34
|
+
remove_dir("#{Dir.pwd}/lib/legion/extensions/#{lex}/transport/queues") if Dir.empty?("#{Dir.pwd}/lib/legion/extensions/#{lex}/transport/queues/")
|
35
|
+
remove_dir("#{Dir.pwd}/lib/legion/extensions/#{lex}/transport") if Dir.empty?("#{Dir.pwd}/lib/legion/extensions/#{lex}/transport")
|
36
|
+
end
|
37
|
+
|
38
|
+
remove_dir("#{Dir.pwd}/spec/queues") if Dir.exist?("#{Dir.pwd}/spec/queues") && Dir.empty?("#{Dir.pwd}/spec/queues")
|
39
|
+
|
40
|
+
nil
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module Legion
|
2
|
+
class Cli
|
3
|
+
module Lex
|
4
|
+
class Runner < 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 'delete :runner', 'deletes a runner'
|
18
|
+
def delete(name)
|
19
|
+
remove_file("lib/legion/extensions/#{lex}/runners/#{name}.rb")
|
20
|
+
remove_file("spec/runners/#{name}_spec.rb")
|
21
|
+
end
|
22
|
+
|
23
|
+
desc 'create name type', 'creates a new runner'
|
24
|
+
def create(name)
|
25
|
+
template('templates/runner.erb', "lib/legion/extensions/#{lex}/runners/#{name}.rb", { name: name, lex: lex })
|
26
|
+
template('templates/runner_spec.erb', "spec/runners/#{name}_spec.rb", { name: name, lex: lex })
|
27
|
+
end
|
28
|
+
|
29
|
+
desc 'add_function new_function_name *args', 'adds new function to runner, args optional'
|
30
|
+
def add_function(name, function, args = nil)
|
31
|
+
@arg_keys = []
|
32
|
+
|
33
|
+
if args.nil?
|
34
|
+
args = '**'
|
35
|
+
else
|
36
|
+
option_args = ''
|
37
|
+
required_args = ''
|
38
|
+
args.split(',').each do |arg|
|
39
|
+
key, value = arg.split('=')
|
40
|
+
@arg_keys.push key.to_s
|
41
|
+
if value.nil? || value.empty?
|
42
|
+
required_args.concat("#{key}:, ")
|
43
|
+
else
|
44
|
+
option_args.concat("#{key}: '#{value}', ")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
args = required_args.concat(option_args, '**')
|
48
|
+
end
|
49
|
+
insert_into_file "lib/legion/extensions/#{lex}/runners/#{name}.rb",
|
50
|
+
after: "extend Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined? 'Helpers::Lex'\n" do
|
51
|
+
"
|
52
|
+
def #{function}(#{args})
|
53
|
+
{ success: true }
|
54
|
+
end\n"
|
55
|
+
end
|
56
|
+
|
57
|
+
insert_into_file("spec/runners/#{name}_spec.rb", after: "it { should be_a Module }\n") do
|
58
|
+
result = " it { is_expected.to respond_to(:#{function}).with_any_keywords }\n"
|
59
|
+
result.concat " it { is_expected.to respond_to(:#{function}).with_keywords(:#{@arg_keys.join(', :')}) }\n" if @arg_keys.count.positive?
|
60
|
+
result
|
61
|
+
end
|
62
|
+
|
63
|
+
insert_into_file("spec/runners/#{name}_spec.rb", before: " end\n") do
|
64
|
+
" it('#{function} returns a success') { expect(test_class.#{function}[:success]).to eq true }\n"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
File without changes
|
@@ -0,0 +1,69 @@
|
|
1
|
+
image: ruby:2.7
|
2
|
+
|
3
|
+
pipelines:
|
4
|
+
tags:
|
5
|
+
"v*":
|
6
|
+
- step:
|
7
|
+
name: Rubocop
|
8
|
+
caches:
|
9
|
+
- bundler
|
10
|
+
script:
|
11
|
+
- gem install rubocop
|
12
|
+
- gem update rubocop
|
13
|
+
- rubocop
|
14
|
+
- step:
|
15
|
+
name: RSpec
|
16
|
+
caches:
|
17
|
+
- bundler
|
18
|
+
script:
|
19
|
+
- gem install bundler
|
20
|
+
- gem update bundler
|
21
|
+
- bundle update
|
22
|
+
- bundle exec rspec
|
23
|
+
- step:
|
24
|
+
name: Push to RubyGems
|
25
|
+
deployment: RubyGems
|
26
|
+
script:
|
27
|
+
- gem install bundler gem-release rspec
|
28
|
+
- bundle install
|
29
|
+
- (umask 077 ; echo $gem_creds | base64 --decode > ~/.gem/credentials)
|
30
|
+
- gem release
|
31
|
+
artifacts:
|
32
|
+
- pkg/**
|
33
|
+
branches:
|
34
|
+
master:
|
35
|
+
- step:
|
36
|
+
caches:
|
37
|
+
- bundler
|
38
|
+
script:
|
39
|
+
- gem install rubocop
|
40
|
+
- gem update rubocop
|
41
|
+
- rubocop
|
42
|
+
- step:
|
43
|
+
caches:
|
44
|
+
- bundler
|
45
|
+
script:
|
46
|
+
- gem install bundler
|
47
|
+
- gem update bundler
|
48
|
+
- bundle update
|
49
|
+
- bundle exec rspec
|
50
|
+
develop:
|
51
|
+
- step:
|
52
|
+
caches:
|
53
|
+
- bundler
|
54
|
+
script:
|
55
|
+
- gem install rubocop
|
56
|
+
- gem update rubocop
|
57
|
+
- rubocop
|
58
|
+
- step:
|
59
|
+
caches:
|
60
|
+
- bundler
|
61
|
+
script:
|
62
|
+
- gem install bundler
|
63
|
+
- gem update bundler
|
64
|
+
- bundle update
|
65
|
+
- bundle exec rspec
|
66
|
+
|
67
|
+
definitions:
|
68
|
+
caches:
|
69
|
+
bundler: /usr/local/bundle
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require_relative 'lib/legion/extensions/<%= config[:lex] %>/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = 'lex-<%= config[:lex] %>'
|
5
|
+
spec.version = Legion::Extensions::<%= config[:class_name] %>::VERSION
|
6
|
+
spec.authors = ['Esity']
|
7
|
+
spec.email = ['matthewdiverson@gmail.com']
|
8
|
+
|
9
|
+
spec.summary = 'LEX::<%= config[:class_name] %>'
|
10
|
+
spec.description = 'Connects Legion to <%= config[:class_name] %>'
|
11
|
+
spec.homepage = 'https://bitbucket.org/legion-io/lex-<%= config[:lex] %>'
|
12
|
+
spec.license = 'MIT'
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.5.0')
|
14
|
+
|
15
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
16
|
+
spec.metadata['source_code_uri'] = 'https://bitbucket.org/legion-io/lex-<%= config[:lex] %>/src'
|
17
|
+
spec.metadata['documentation_uri'] = 'https://legionio.atlassian.net/wiki/spaces/LEX/pages/'
|
18
|
+
spec.metadata['changelog_uri'] = 'https://legionio.atlassian.net/wiki/spaces/LEX/pages/'
|
19
|
+
spec.metadata['bug_tracker_uri'] = 'https://bitbucket.org/legion-io/lex-<%= config[:lex] %>/issues'
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_development_dependency 'rake'
|
23
|
+
spec.add_development_dependency 'rspec'
|
24
|
+
spec.add_development_dependency 'rubocop'
|
25
|
+
spec.add_development_dependency 'simplecov'
|
26
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Esity
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
@@ -0,0 +1,15 @@
|
|
1
|
+
Metrics/LineLength:
|
2
|
+
Max: 120
|
3
|
+
Metrics/MethodLength:
|
4
|
+
Max: 30
|
5
|
+
Metrics/ClassLength:
|
6
|
+
Max: 1500
|
7
|
+
Style/Documentation:
|
8
|
+
Enabled: false
|
9
|
+
AllCops:
|
10
|
+
TargetRubyVersion: 2.5
|
11
|
+
NewCops: enable
|
12
|
+
Style/FrozenStringLiteralComment:
|
13
|
+
Enabled: false
|
14
|
+
Naming/FileName:
|
15
|
+
Enabled: false
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'legion/extensions/<%= config[:lex] %>'
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
config.example_status_persistence_file_path = '.rspec_status'
|
6
|
+
config.disable_monkey_patching!
|
7
|
+
|
8
|
+
config.expect_with :rspec do |c|
|
9
|
+
c.syntax = :expect
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Legion::Extensions::<%= config[:lex].split('_').collect(&:capitalize).join %>
|
2
|
+
module Transport
|
3
|
+
module Exchanges
|
4
|
+
class <%= config[:name].split('_').collect(&:capitalize).join %> < Legion::Transport::Exchange
|
5
|
+
def exchange_name
|
6
|
+
'<%= config[:name].split('_').collect(&:capitalize).join %>'
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
File without changes
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Legion::Extensions::<%= config[:lex].split('_').collect(&:capitalize).join %>
|
2
|
+
module Transport
|
3
|
+
module Messages
|
4
|
+
class <%= config[:name].split('_').collect(&:capitalize).join %> < Legion::Transport::Message
|
5
|
+
def initialize(payload, status, options = {})
|
6
|
+
@payload = payload
|
7
|
+
@options = options
|
8
|
+
@status = status
|
9
|
+
@routing_key = routing_key
|
10
|
+
validate
|
11
|
+
end
|
12
|
+
|
13
|
+
def routing_key
|
14
|
+
"<%= config[:lex].split('_').collect(&:capitalize).join %>.<%= config[:name].split('_').collect(&:capitalize).join %>"
|
15
|
+
end
|
16
|
+
|
17
|
+
def message(payload = @payload, _options = {})
|
18
|
+
Legion::JSON.dump(payload)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
File without changes
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Legion
|
2
|
+
module Extensions
|
3
|
+
module <%= config[:lex].split('_').collect(&:capitalize).join %>
|
4
|
+
module Transport
|
5
|
+
module Queues
|
6
|
+
class <%= config[:name].split('_').collect(&:capitalize).join %> < Legion::Transport::Queue
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Legion
|
2
|
+
module Transport
|
3
|
+
class Queue
|
4
|
+
def initialize(**opts)
|
5
|
+
end
|
6
|
+
|
7
|
+
def queue_name
|
8
|
+
'test_queue'
|
9
|
+
end
|
10
|
+
|
11
|
+
def acknowledge(delivery_tag)
|
12
|
+
true
|
13
|
+
end
|
14
|
+
|
15
|
+
def reject(delivery_tag, requeue: false, **)
|
16
|
+
true
|
17
|
+
end
|
18
|
+
|
19
|
+
def queue_options
|
20
|
+
Concurrent::Hash.new
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'queue_helper'
|
3
|
+
require 'legion/extensions/<%= config[:lex] %>/transport/queues/<%= config[:name] %>'
|
4
|
+
|
5
|
+
RSpec.describe Legion::Extensions::<%= config[:lex].split('_').collect(&:capitalize).join %>::Transport::Queues::<%= config[:name].capitalize %> do
|
6
|
+
it { should be_a Legion::Transport::Queue }
|
7
|
+
it { should respond_to :queue_name }
|
8
|
+
it { should respond_to(:acknowledge).with(1).argument }
|
9
|
+
it { should respond_to(:reject).with(1).argument }
|
10
|
+
it { should respond_to :queue_options }
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Legion
|
2
|
+
module Extensions
|
3
|
+
module <%= config[:lex].split('_').collect(&:capitalize).join %>
|
4
|
+
module Runners
|
5
|
+
module <%= config[:name].split('_').collect(&:capitalize).join %>
|
6
|
+
extend Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined? 'Helpers::Lex'
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'legion/extensions/<%= config[:lex] %>/runners/<%= config[:name] %>'
|
3
|
+
|
4
|
+
RSpec.describe Legion::Extensions::<%= config[:lex].split('_').collect(&:capitalize).join %>::Runners::<%= config[:name].capitalize %> do
|
5
|
+
it { should be_a Module }
|
6
|
+
Legion::Extensions::<%= config[:lex].capitalize %>::Runners::<%= config[:name].split('_').collect(&:capitalize).join %>.extend Legion::Extensions::<%= config[:lex].split('_').collect(&:capitalize).join %>::Runners::<%= config[:name].split('_').collect(&:capitalize).join %>
|
7
|
+
|
8
|
+
describe 'Functions should work with arguments' do
|
9
|
+
let(:test_class) { Class.new { extend Legion::Extensions::<%= config[:lex].split('_').collect(&:capitalize).join %>::Runners::<%= config[:name].split('_').collect(&:capitalize).join %> } }
|
10
|
+
end
|
11
|
+
end
|