shatter-rb 0.0.2 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.husky/commit-msg +5 -0
- data/.rubocop.yml +4 -0
- data/.ruby-version +1 -1
- data/.tool-versions +1 -1
- data/Gemfile +0 -2
- data/Gemfile.lock +51 -8
- data/Guardfile +72 -0
- data/README.md +72 -14
- data/commitlint.config.js +1 -0
- data/example_app/Gemfile +3 -2
- data/example_app/Gemfile.lock +9 -16
- data/example_app/app/application.rb +4 -0
- data/example_app/app/functions/hello_world_function.rb +8 -16
- data/example_app/app/service_definition.rb +2 -6
- data/example_app/application.rb +4 -2
- data/example_app/bin/service +2 -2
- data/example_app/config/environment.rb +13 -7
- data/example_app/config.ru +8 -0
- data/exe/console +1 -1
- data/exe/shatter +55 -25
- data/lib/shatter/config.rb +14 -4
- data/lib/shatter/service/base.rb +28 -35
- data/lib/shatter/service/discovery.rb +32 -19
- data/lib/shatter/service/function.rb +45 -31
- data/lib/shatter/service/response_pool.rb +12 -7
- data/lib/shatter/service/service_definition.rb +10 -4
- data/lib/shatter/util.rb +21 -5
- data/lib/shatter/version.rb +1 -1
- data/lib/shatter/web/application.rb +34 -32
- data/lib/shatter/web/server.rb +25 -18
- data/lib/shatter.rb +59 -11
- data/package.json +7 -0
- data/templates/Gemfile.template +1 -3
- data/templates/application.erb +2 -6
- data/templates/config.ru +8 -0
- data/templates/environment.rb.erb +9 -8
- data/templates/function_definition.ts.erb +5 -0
- data/templates/hello_world_function.rb.erb +6 -14
- data/templates/service_client.ts.erb +25 -0
- data/templates/service_definition.rb.erb +3 -7
- data/yarn.lock +1338 -0
- metadata +115 -25
- data/example_app/bin/console +0 -11
- data/lib/shatter/service/function_params.rb +0 -21
- data/shatter.gemspec +0 -51
@@ -1,9 +1,10 @@
|
|
1
|
-
Shatter
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
Shatter.config do |config|
|
2
|
+
config.zookeeper_host = "localhost:2181"
|
3
|
+
config.initial_delay = 100
|
4
|
+
config.missing_result_delay = 100
|
5
|
+
config.service_port = ENV.fetch('SHATTER_SERVICE_PORT') { 8787 }
|
6
|
+
config.autoload_paths = %w( app app/functions )
|
7
|
+
config.reload_classes = true
|
8
|
+
end
|
5
9
|
|
6
|
-
|
7
|
-
|
8
|
-
Shatter::Service::Base.service_definition = <%= app_name%>::ServiceDefinition
|
9
|
-
Shatter::Web::Server.application = <%= app_name%>::Application
|
10
|
+
Shatter.load
|
@@ -1,17 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
class HelloWorldFunction < Shatter::Service::Function
|
2
|
+
define_param :name, nullable: false, type: 'string'
|
3
|
+
define_param :number, nullable: false, type: 'integer'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
define_param :name, nullable: false, type: 'string'
|
9
|
-
define_param :number, nullable: false, type: 'integer'
|
10
|
-
|
11
|
-
def invoke
|
12
|
-
params.to_h => name:, uuid:
|
13
|
-
{ result: "Hello #{name}", uuid:, error: nil, uuid: }
|
14
|
-
end
|
15
|
-
end
|
5
|
+
def invoke
|
6
|
+
params.to_h => name:, uuid:
|
7
|
+
{ result: "Hello #{name}", error: nil, uuid: }
|
16
8
|
end
|
17
9
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import { ShatterClient } from 'shatter-client'
|
2
|
+
|
3
|
+
interface ShatterResult {
|
4
|
+
result: string | number | Array<any> | object,
|
5
|
+
error: string | null
|
6
|
+
uuid: string
|
7
|
+
}
|
8
|
+
|
9
|
+
class AppClient {
|
10
|
+
client: ShatterClient;
|
11
|
+
|
12
|
+
constructor(host: string){
|
13
|
+
this.client = new ShatterClient(host)
|
14
|
+
}
|
15
|
+
|
16
|
+
async makeRequest<responseType>(operation : string, params : object) : Promise<responseType> {
|
17
|
+
return await this.client.invokeRPC(operation,params) as responseType;
|
18
|
+
}
|
19
|
+
}
|
20
|
+
|
21
|
+
class Client extends AppClient {
|
22
|
+
<%= function_defs.map(&:to_typescript).join("\n") %>
|
23
|
+
}
|
24
|
+
|
25
|
+
export default Client;
|
@@ -1,9 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
class ServiceDefinition < Shatter::Service::ServiceDefinition
|
7
|
-
register_function :hello_world, <%= app_name %>::Functions::HelloWorldFunction
|
8
|
-
end
|
9
|
-
end
|
3
|
+
class ServiceDefinition < Shatter::Service::ServiceDefinition
|
4
|
+
register_function :hello_world, HelloWorldFunction
|
5
|
+
end
|