alain 0.4.1 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/alain +6 -5
- data/lib/alain/cargo.rb +16 -11
- data/lib/alain/driver.rb +13 -12
- data/lib/alain/proto.rb +1 -1
- data/lib/alain/templates/integration_test.rs.erb +1 -3
- data/lib/alain/templates/lib.rs.erb +4 -8
- data/lib/alain/templates/main.rs.erb +5 -2
- data/lib/alain/templates/mod.rs.erb +7 -7
- data/lib/alain/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c267e3d5de58262224561ea0d8ba30001b34fab33555dc51504964ba3452bdf3
|
4
|
+
data.tar.gz: 9ce081427153f8bcca6ad045ad5e670fb459c9b3eee6308b67fa4e7a625b4b7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca631fe453cc076045716207acd64bc2fc4cec1cec873747c17ecfca155cfe9f31625d678a893f21ad1fa7cb49460c9f1ec889998ce7e99ed6f99ea058da8248
|
7
|
+
data.tar.gz: aefd56ebb7d94be2254cc98c013afadaafe09ffb79cd08b8bc85db4ce02a415884d738c9a2ad06adbe74b7b593af1258fd902f41be644f32a135a1b9bd6e7cfa
|
data/exe/alain
CHANGED
@@ -7,7 +7,7 @@ require 'alain'
|
|
7
7
|
class AlainCmd
|
8
8
|
def self.generate(args, params)
|
9
9
|
if check_git || params[:force_overwrite]
|
10
|
-
Alain::Driver.new(args[0]).generate(params[:update_server])
|
10
|
+
Alain::Driver.new(args[0]).generate(params[:update_server], params[:server_conf])
|
11
11
|
else
|
12
12
|
exit 1
|
13
13
|
end
|
@@ -19,15 +19,15 @@ class AlainCmd
|
|
19
19
|
rescue
|
20
20
|
end
|
21
21
|
unless s == 0
|
22
|
-
puts "Requires git repository. If your sure, you can use '--force' option"
|
23
|
-
puts 'Exit'
|
22
|
+
STDERR.puts "Requires git repository. If your sure, you can use '--force' option"
|
23
|
+
STDERR.puts 'Exit'
|
24
24
|
return false
|
25
25
|
end
|
26
26
|
|
27
27
|
o, _, _ = Open3.capture3('git status -s | wc -l')
|
28
28
|
unless o.to_i == 0
|
29
|
-
puts "Commit working diffs before running. If your sure, you can use '--force' option."
|
30
|
-
puts 'Exit'
|
29
|
+
STDERR.puts "Commit working diffs before running. If your sure, you can use '--force' option."
|
30
|
+
STDERR.puts 'Exit'
|
31
31
|
return false
|
32
32
|
end
|
33
33
|
true
|
@@ -41,6 +41,7 @@ OptionParser.new do |opt|
|
|
41
41
|
opt.banner = 'Usage: alain [options] proto_file'
|
42
42
|
opt.on('--force', 'force generate files') { |_v| params[:force_overwrite] = true }
|
43
43
|
opt.on('--update-server', 'Overwrite main.rs/lib.rs with reference server') { |_v| params[:update_server] = true }
|
44
|
+
opt.on('--use-server-conf', 'introduce github.com/chumaltd/server-util') { |_v| params[:server_conf] = true }
|
44
45
|
args = opt.parse!(ARGV)
|
45
46
|
AlainCmd.generate(args, params)
|
46
47
|
end
|
data/lib/alain/cargo.rb
CHANGED
@@ -8,20 +8,20 @@ module Alain #:nodoc:
|
|
8
8
|
def initialize(dir = '.')
|
9
9
|
toml = Pathname(dir) / 'Cargo.toml'
|
10
10
|
unless File.exist? toml
|
11
|
-
puts "./Cargo.toml not found. 'cargo
|
11
|
+
STDERR.puts "./Cargo.toml not found. 'cargo init' first."
|
12
12
|
exit 1
|
13
13
|
end
|
14
14
|
@cargo = Tomlrb.load_file toml
|
15
15
|
end
|
16
16
|
|
17
|
-
def add_dependencies
|
17
|
+
def add_dependencies(server_conf: false)
|
18
18
|
toml = Pathname('.') / 'Cargo.toml'
|
19
19
|
origin = File.read toml
|
20
20
|
File.open(toml, 'w') do |f|
|
21
21
|
origin.each_line do |line|
|
22
22
|
if /^\[dependencies\]/.match(line)
|
23
23
|
f.puts line
|
24
|
-
dependencies.each do |k, entry|
|
24
|
+
dependencies(server_conf).each do |k, entry|
|
25
25
|
next if @cargo['dependencies'].keys.include? k
|
26
26
|
f.puts entry
|
27
27
|
end
|
@@ -48,23 +48,28 @@ module Alain #:nodoc:
|
|
48
48
|
|
49
49
|
private
|
50
50
|
|
51
|
-
def dependencies
|
51
|
+
def dependencies(server_conf)
|
52
52
|
{
|
53
|
-
'
|
54
|
-
'prost' => %(prost = "0.
|
55
|
-
'prost-types' => %(prost-types = "0.7"),
|
53
|
+
'prost' => %(prost = "0.10"),
|
54
|
+
'prost-types' => %(prost-types = "0.10"),
|
56
55
|
'signal-hook' => %(signal-hook = "0.3.9"),
|
57
56
|
'signal-hook-tokio' => %(signal-hook-tokio = { version = "0.3.0", features = ["futures-v0_3"] }),
|
58
57
|
'tokio' => %(tokio = { version = "1.0", features = ["full"] }),
|
59
58
|
'tokio-stream' => %(tokio-stream = "0.1.2"),
|
60
|
-
'tonic' => %(tonic = "0.
|
61
|
-
'triggered' => %(triggered = "0.1.
|
62
|
-
}
|
59
|
+
'tonic' => %(tonic = "0.7"),
|
60
|
+
'triggered' => %(triggered = "0.1.2")
|
61
|
+
}.tap do |dep|
|
62
|
+
if server_conf
|
63
|
+
dep['server-conf'] = %(server-conf = { git = "https://github.com/chumaltd/server-util.git" })
|
64
|
+
else
|
65
|
+
dep['once_cell'] = %(once_cell = "1.5")
|
66
|
+
end
|
67
|
+
end
|
63
68
|
end
|
64
69
|
|
65
70
|
def build_dependencies
|
66
71
|
{
|
67
|
-
'tonic-build' => %(tonic-build = { version = "0.
|
72
|
+
'tonic-build' => %(tonic-build = { version = "0.6", features = ["prost"] }),
|
68
73
|
}
|
69
74
|
end
|
70
75
|
end
|
data/lib/alain/driver.rb
CHANGED
@@ -16,32 +16,33 @@ module Alain #:nodoc:
|
|
16
16
|
@svc_code = SvcCode.new proto.service_name(:snake)
|
17
17
|
end
|
18
18
|
|
19
|
-
def generate(update_server = false)
|
19
|
+
def generate(update_server = false, server_conf = false)
|
20
|
+
@server_conf = server_conf
|
20
21
|
if @svc_code.exist?
|
21
|
-
puts 'Already exists service definition. Only update methods...'
|
22
|
+
STDERR.puts 'Already exists service definition. Only update methods...'
|
22
23
|
update_svc
|
23
24
|
else
|
24
25
|
update_server = true
|
25
|
-
puts 'No service definition yet...'
|
26
|
-
puts 'Generate service definition'
|
26
|
+
STDERR.puts 'No service definition yet...'
|
27
|
+
STDERR.puts 'Generate service definition'
|
27
28
|
parse_svc
|
28
29
|
end
|
29
30
|
if update_server
|
30
|
-
puts 'Overwrite main.rs'
|
31
|
+
STDERR.puts 'Overwrite main.rs'
|
31
32
|
parse_erb 'main.rs'
|
32
|
-
puts 'Overwrite lib.rs'
|
33
|
+
STDERR.puts 'Overwrite lib.rs'
|
33
34
|
parse_erb 'lib.rs'
|
34
|
-
puts 'Generate build.rs'
|
35
|
+
STDERR.puts 'Generate build.rs'
|
35
36
|
parse_erb 'build.rs', '', '.'
|
36
|
-
puts 'Generate tests/common/mod.rs'
|
37
|
+
STDERR.puts 'Generate tests/common/mod.rs'
|
37
38
|
FileUtils.mkdir_p 'tests/common/'
|
38
39
|
parse_erb 'mod.rs', '', 'tests/common'
|
39
|
-
puts 'Generate tests/integration_test.rs'
|
40
|
+
STDERR.puts 'Generate tests/integration_test.rs'
|
40
41
|
parse_erb 'integration_test.rs', '', 'tests'
|
41
|
-
puts 'Update Cargo.toml'
|
42
|
-
cargo.add_dependencies
|
42
|
+
STDERR.puts 'Update Cargo.toml'
|
43
|
+
cargo.add_dependencies(server_conf: @server_conf)
|
43
44
|
end
|
44
|
-
puts 'Done'
|
45
|
+
STDERR.puts 'Done'
|
45
46
|
end
|
46
47
|
|
47
48
|
private
|
data/lib/alain/proto.rb
CHANGED
@@ -1,14 +1,12 @@
|
|
1
1
|
mod common;
|
2
2
|
use common::setup;
|
3
|
-
use triggered::trigger;
|
4
3
|
|
5
4
|
<%= proto.use_def(cargo.crate_name) %>
|
6
5
|
use <%= cargo.crate_name %>::<%= proto.package %>::<%= proto.service_name(:snake) %>_client::<%= proto.service_name %>Client;
|
7
6
|
|
8
7
|
#[tokio::test]
|
9
8
|
async fn it_returns_ok_response() {
|
10
|
-
let (
|
11
|
-
let (jh, channel) = setup(shutdown_signal).await.unwrap();
|
9
|
+
let (jh, channel, shutdown_trigger) = setup().await.unwrap();
|
12
10
|
|
13
11
|
let mut client = <%= proto.service_name %>Client::new(channel);
|
14
12
|
// TODO: implement gRPC client request
|
@@ -13,17 +13,13 @@ mod <%= proto.service_name :snake %>_service;
|
|
13
13
|
use self::<%= proto.service_name :snake %>_service::<%= proto.service_name %>Service;
|
14
14
|
|
15
15
|
pub async fn start_server(addr: SocketAddr, signal: Listener) -> Result<(), Box<dyn std::error::Error>> {
|
16
|
-
println!("ready");
|
17
|
-
create_router().await
|
18
|
-
.serve_with_shutdown(addr, signal).await.unwrap();
|
19
|
-
|
20
|
-
Ok(())
|
21
|
-
}
|
22
|
-
|
23
|
-
pub async fn create_router() -> Router<<%= proto.service_name %>Server<<%= proto.service_name %>Service>, tonic::transport::server::Unimplemented> {
|
24
16
|
let server = <%= proto.service_name %>Service{};
|
17
|
+
println!("{} {} ready, Listen {}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"), addr);
|
25
18
|
Server::builder()
|
26
19
|
.add_service(<%= proto.service_name %>Server::new(server))
|
20
|
+
.serve_with_shutdown(addr, signal).await.unwrap();
|
21
|
+
|
22
|
+
Ok(())
|
27
23
|
}
|
28
24
|
|
29
25
|
pub async fn handle_signals(signals: Signals, trigger: triggered::Trigger) {
|
@@ -1,12 +1,15 @@
|
|
1
|
-
use once_cell::sync::Lazy;
|
2
1
|
use signal_hook::consts::signal::*;
|
3
2
|
use signal_hook_tokio::Signals;
|
4
3
|
use <%= cargo.crate_name %>::{start_server, handle_signals};
|
5
|
-
|
4
|
+
<% if @server_conf -%>
|
5
|
+
use server_conf::SERVER_BIND;
|
6
|
+
<% else -%>
|
7
|
+
use once_cell::sync::Lazy;
|
6
8
|
pub static SERVER_BIND: Lazy<std::net::SocketAddr> = Lazy::new(|| {
|
7
9
|
format!("{}:{}", "0.0.0.0", 50051)
|
8
10
|
.parse().unwrap()
|
9
11
|
});
|
12
|
+
<% end -%>
|
10
13
|
|
11
14
|
#[tokio::main]
|
12
15
|
pub async fn main() {
|
@@ -2,13 +2,14 @@
|
|
2
2
|
use std::time::Duration;
|
3
3
|
use tokio::task::JoinHandle;
|
4
4
|
use tonic::{transport::Channel, Status};
|
5
|
-
use
|
5
|
+
use triggered::{trigger, Trigger};
|
6
|
+
use <%= cargo.crate_name %>::start_server;
|
6
7
|
|
7
|
-
pub async fn setup(
|
8
|
+
pub async fn setup() -> Result<(JoinHandle<()>, Channel, Trigger), Box<dyn std::error::Error>> {
|
9
|
+
let (shutdown_trigger, signal) = trigger();
|
8
10
|
let srv: JoinHandle<()> = tokio::spawn(async move {
|
9
11
|
// Launch gRPC server
|
10
|
-
|
11
|
-
.serve_with_shutdown("127.0.0.1:50051".parse().unwrap(), signal)
|
12
|
+
start_server("127.0.0.1:50051".parse().unwrap(), signal)
|
12
13
|
.await.unwrap()
|
13
14
|
});
|
14
15
|
|
@@ -18,8 +19,7 @@ pub async fn setup(signal: triggered::Listener) -> Result<(JoinHandle<()>, Chann
|
|
18
19
|
let channel = Channel::from_static("http://127.0.0.1:50051")
|
19
20
|
.timeout(Duration::from_secs(30))
|
20
21
|
.concurrency_limit(20)
|
21
|
-
.connect_lazy()
|
22
|
-
.or_else(|_e| Err(Status::cancelled("client connection error")))?;
|
22
|
+
.connect_lazy();
|
23
23
|
|
24
|
-
Ok((srv, channel))
|
24
|
+
Ok((srv, channel, shutdown_trigger))
|
25
25
|
}
|
data/lib/alain/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alain
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chuma Takahiro
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-06-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tomlrb
|
@@ -53,7 +53,7 @@ metadata:
|
|
53
53
|
homepage_uri: https://github.com/chumaltd/alain
|
54
54
|
source_code_uri: https://github.com/chumaltd/alain
|
55
55
|
changelog_uri: https://github.com/chumaltd/alain/blob/main/CHANGELOG.md
|
56
|
-
post_install_message:
|
56
|
+
post_install_message:
|
57
57
|
rdoc_options: []
|
58
58
|
require_paths:
|
59
59
|
- lib
|
@@ -68,8 +68,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: '0'
|
70
70
|
requirements: []
|
71
|
-
rubygems_version: 3.
|
72
|
-
signing_key:
|
71
|
+
rubygems_version: 3.3.5
|
72
|
+
signing_key:
|
73
73
|
specification_version: 4
|
74
74
|
summary: Code generator for rust prost
|
75
75
|
test_files: []
|