peplum-template 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/console +11 -0
- data/bin/setup +8 -0
- data/examples/rest/helpers.rb +44 -0
- data/examples/rest.rb +56 -0
- data/examples/rpc.rb +29 -0
- data/lib/peplum/template/application/native.rb +53 -0
- data/lib/peplum/template/application/services/my_service.rb +20 -0
- data/lib/peplum/template/application.rb +28 -0
- data/lib/peplum/template/version.rb +7 -0
- data/lib/peplum/template.rb +15 -0
- data/peplum-template.gemspec +23 -0
- metadata +67 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c0d6c39c431c4ade9a4d96500048847342b80a0a15c5d4f7cfe123278662bb0f
|
4
|
+
data.tar.gz: bf8d5f760b771c9409c49befdff81a2c58403142d62a9b6276397cc93f7183ee
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9b4f72c06b677097b32268507e4f57a84ff5785b363b3fd1370aacac342efd8c1eaa15c73599eca14b7c027e44789cf1472c2f850c3c11c893ef3111e0763735
|
7
|
+
data.tar.gz: ba15f06884e7646db3f7d96b4f06baf606b0ebe9db82d40e56aba2d3516c76289f5d734b5a40e03eca3a88e27e8006e2a28daa5dc4c8d75fe0078aea6e508d60
|
data/bin/console
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "peplum/template"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
require "irb"
|
11
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'tmpdir'
|
3
|
+
require 'net/http'
|
4
|
+
|
5
|
+
def response
|
6
|
+
if @last_response['Content-Type'].include? 'json'
|
7
|
+
data = JSON.load( @last_response.body )
|
8
|
+
else
|
9
|
+
data = @last_response.body
|
10
|
+
end
|
11
|
+
{
|
12
|
+
code: @last_response.code,
|
13
|
+
data: data
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
def response_data
|
18
|
+
response[:data]
|
19
|
+
end
|
20
|
+
|
21
|
+
def request( method, resource = nil, parameters = nil )
|
22
|
+
uri = URI( "http://127.0.0.1:7331/#{resource}" )
|
23
|
+
|
24
|
+
Net::HTTP.start( uri.host, uri.port) do |http|
|
25
|
+
case method
|
26
|
+
when :get
|
27
|
+
uri.query = URI.encode_www_form( parameters ) if parameters
|
28
|
+
request = Net::HTTP::Get.new( uri )
|
29
|
+
|
30
|
+
when :post
|
31
|
+
request = Net::HTTP::Post.new( uri )
|
32
|
+
request.body = parameters.to_json
|
33
|
+
|
34
|
+
when :delete
|
35
|
+
request = Net::HTTP::Delete.new( uri )
|
36
|
+
|
37
|
+
when :put
|
38
|
+
request = Net::HTTP::Put.new( uri )
|
39
|
+
request.body = parameters.to_json
|
40
|
+
end
|
41
|
+
|
42
|
+
@last_response = http.request( request )
|
43
|
+
end
|
44
|
+
end
|
data/examples/rest.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'peplum/template'
|
2
|
+
require 'pp'
|
3
|
+
require_relative 'rest/helpers'
|
4
|
+
|
5
|
+
# Boot up our REST server for easy integration.
|
6
|
+
rest_pid = Peplum::Template::Application.spawn( :rest, daemonize: true )
|
7
|
+
at_exit { Cuboid::Processes::Manager.kill rest_pid }
|
8
|
+
|
9
|
+
# Wait for the REST server to boot up.
|
10
|
+
while sleep 1
|
11
|
+
begin
|
12
|
+
request :get
|
13
|
+
rescue Errno::ECONNREFUSED
|
14
|
+
next
|
15
|
+
end
|
16
|
+
|
17
|
+
break
|
18
|
+
end
|
19
|
+
|
20
|
+
# Assign an Agent to the REST service for it to provide us with Instances.
|
21
|
+
template_agent = Peplum::Template::Application.spawn( :agent, daemonize: true )
|
22
|
+
request :put, 'agent/url', template_agent.url
|
23
|
+
at_exit { template_agent.shutdown rescue nil }
|
24
|
+
|
25
|
+
# Create a new Instance and run with the following options.
|
26
|
+
request :post, 'instances', {
|
27
|
+
peplum: {
|
28
|
+
objects: [1, 2, 3, 4, 5, 6, 7, 8, 9, 0],
|
29
|
+
max_workers: 5
|
30
|
+
},
|
31
|
+
native: {
|
32
|
+
my_option_bool: true,
|
33
|
+
my_option_array: [1,2,3],
|
34
|
+
my_option_hash: { 4 => '5', '6' => 7 }
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
# The ID is used to represent that instance and allow us to manage it from here on out.
|
39
|
+
instance_id = response_data['id']
|
40
|
+
|
41
|
+
while sleep( 1 )
|
42
|
+
# Continue looping while instance status is 'busy'.
|
43
|
+
request :get, "instances/#{instance_id}"
|
44
|
+
break if !response_data['busy']
|
45
|
+
end
|
46
|
+
|
47
|
+
puts '*' * 88
|
48
|
+
|
49
|
+
# Get the report.
|
50
|
+
request :get, "instances/#{instance_id}/report.json"
|
51
|
+
|
52
|
+
# Print out the report.
|
53
|
+
puts JSON.pretty_generate( JSON.load( response_data['data'] ) )
|
54
|
+
|
55
|
+
# Shutdown the Instance.
|
56
|
+
request :delete, "instances/#{instance_id}"
|
data/examples/rpc.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'pp'
|
2
|
+
require 'peplum/template'
|
3
|
+
|
4
|
+
# Spawn an Agent as a daemon.
|
5
|
+
template_agent = Peplum::Template::Application.spawn( :agent, daemonize: true )
|
6
|
+
at_exit { template_agent.shutdown rescue nil }
|
7
|
+
|
8
|
+
# Spawn and connect to an Instance.
|
9
|
+
template = Peplum::Template::Application.connect( template_agent.spawn )
|
10
|
+
# Don't forget this!
|
11
|
+
at_exit { template.shutdown }
|
12
|
+
|
13
|
+
template.run(
|
14
|
+
peplum: {
|
15
|
+
objects: [1, 2, 3, 4, 5, 6, 7, 8, 9, 0],
|
16
|
+
max_workers: 5
|
17
|
+
},
|
18
|
+
native: {
|
19
|
+
my_option_bool: true,
|
20
|
+
my_option_array: [1,2,3],
|
21
|
+
my_option_hash: { 4 => '5', '6' => 7 }
|
22
|
+
}
|
23
|
+
)
|
24
|
+
|
25
|
+
# Waiting to complete.
|
26
|
+
sleep 1 while template.running?
|
27
|
+
|
28
|
+
# Hooray!
|
29
|
+
puts JSON.pretty_generate( template.generate_report.data )
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Peplum
|
2
|
+
class Template
|
3
|
+
class Application
|
4
|
+
|
5
|
+
module Native
|
6
|
+
|
7
|
+
# TODO: Populate it with some actual payload code.
|
8
|
+
#
|
9
|
+
# Run payload against `objects` based on given `options`
|
10
|
+
#
|
11
|
+
# @param [Array] objects Objects that this worker should process.
|
12
|
+
# @param [Hash, NilClass] options Worker options.
|
13
|
+
# @abstract
|
14
|
+
def run( objects, options )
|
15
|
+
# Signal that we started work or something to our peers...
|
16
|
+
Template::Application.shared_hash.set( Process.pid, options )
|
17
|
+
|
18
|
+
# Access peer's services.
|
19
|
+
Template::Application.peers.each do |peer|
|
20
|
+
p peer.my_service.foo
|
21
|
+
pp peer.my_service.shared_hash_to_hash
|
22
|
+
end
|
23
|
+
|
24
|
+
pp [objects, options]
|
25
|
+
end
|
26
|
+
|
27
|
+
# Distribute `objects` into `chunks` amount of groups, one for each worker.
|
28
|
+
#
|
29
|
+
# @param [Array] objects All objects that need to be processed.
|
30
|
+
# @param [Integer] chunks Amount of object groups that should be generated.
|
31
|
+
#
|
32
|
+
# @return [Array<Array<Object>>] `objects` split in `chunks` amount of groups
|
33
|
+
# @abstract
|
34
|
+
def group( objects, chunks )
|
35
|
+
objects.chunk chunks
|
36
|
+
end
|
37
|
+
|
38
|
+
# TODO: Populate it with some actual merging code.
|
39
|
+
#
|
40
|
+
# Merge result `data` for reporting.
|
41
|
+
#
|
42
|
+
# @param [Array] data Report data from workers.
|
43
|
+
# @abstract
|
44
|
+
def merge( data )
|
45
|
+
data
|
46
|
+
end
|
47
|
+
|
48
|
+
extend self
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'peplum'
|
4
|
+
|
5
|
+
module Peplum
|
6
|
+
class Template
|
7
|
+
|
8
|
+
class Application < Peplum::Application
|
9
|
+
require_relative "application/native"
|
10
|
+
require_relative 'application/services/my_service'
|
11
|
+
|
12
|
+
# TODO: Adjust accordingly.
|
13
|
+
provision_memory 100 * 1024 * 1024
|
14
|
+
|
15
|
+
# TODO: Adjust accordingly.
|
16
|
+
provision_disk 100 * 1024 * 1024
|
17
|
+
|
18
|
+
# TODO: Is a service necessary?
|
19
|
+
instance_service_for :my_service, Services::MyService
|
20
|
+
|
21
|
+
def native_app
|
22
|
+
Native
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/peplum/template/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "peplum-template"
|
7
|
+
spec.version = Peplum::Template::VERSION
|
8
|
+
spec.authors = ["Tasos Laskos"]
|
9
|
+
spec.email = ["tasos.laskos@ecsypno.com"]
|
10
|
+
|
11
|
+
spec.summary = "Peplum template project."
|
12
|
+
spec.description = "Peplum template project."
|
13
|
+
spec.homepage = "http://ecsypno.com/"
|
14
|
+
spec.required_ruby_version = ">= 2.6.0"
|
15
|
+
|
16
|
+
spec.files = Dir.glob( 'bin/*')
|
17
|
+
spec.files += Dir.glob( 'lib/**/*')
|
18
|
+
spec.files += Dir.glob( 'examples/**/*')
|
19
|
+
spec.files += %w(peplum-template.gemspec)
|
20
|
+
|
21
|
+
|
22
|
+
spec.add_dependency "peplum"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: peplum-template
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tasos Laskos
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-05-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: peplum
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Peplum template project.
|
28
|
+
email:
|
29
|
+
- tasos.laskos@ecsypno.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- bin/console
|
35
|
+
- bin/setup
|
36
|
+
- examples/rest.rb
|
37
|
+
- examples/rest/helpers.rb
|
38
|
+
- examples/rpc.rb
|
39
|
+
- lib/peplum/template.rb
|
40
|
+
- lib/peplum/template/application.rb
|
41
|
+
- lib/peplum/template/application/native.rb
|
42
|
+
- lib/peplum/template/application/services/my_service.rb
|
43
|
+
- lib/peplum/template/version.rb
|
44
|
+
- peplum-template.gemspec
|
45
|
+
homepage: http://ecsypno.com/
|
46
|
+
licenses: []
|
47
|
+
metadata: {}
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 2.6.0
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
requirements: []
|
63
|
+
rubygems_version: 3.4.13
|
64
|
+
signing_key:
|
65
|
+
specification_version: 4
|
66
|
+
summary: Peplum template project.
|
67
|
+
test_files: []
|