Skip to content

Commit

Permalink
Merge pull request #62 from iawia002/response
Browse files Browse the repository at this point in the history
wacker: return program id in Run and Serve interfaces
  • Loading branch information
iawia002 authored Apr 19, 2024
2 parents 6f85b88 + cb9a40d commit fb707fc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
8 changes: 6 additions & 2 deletions wacker/proto/wacker.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import "google/protobuf/empty.proto";
package wacker;

service Wacker {
rpc Run (RunRequest) returns (google.protobuf.Empty);
rpc Serve (ServeRequest) returns (google.protobuf.Empty);
rpc Run (RunRequest) returns (ProgramResponse);
rpc Serve (ServeRequest) returns (ProgramResponse);
rpc List (google.protobuf.Empty) returns (ListResponse);
rpc Stop (StopRequest) returns (google.protobuf.Empty);
rpc Restart (RestartRequest) returns (google.protobuf.Empty);
Expand All @@ -23,6 +23,10 @@ message ServeRequest {
string addr = 2;
}

message ProgramResponse {
string id = 1;
}

message Program {
string id = 1;
string path = 2;
Expand Down
2 changes: 1 addition & 1 deletion wacker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use tower::service_fn;
pub use self::config::*;
pub use self::proto::{
wacker_client::WackerClient, wacker_server::Wacker, wacker_server::WackerServer, DeleteRequest, ListResponse,
LogRequest, LogResponse, Program, RestartRequest, RunRequest, ServeRequest, StopRequest,
LogRequest, LogResponse, Program, ProgramResponse, RestartRequest, RunRequest, ServeRequest, StopRequest,
};
pub use self::server::*;

Expand Down
16 changes: 8 additions & 8 deletions wacker/src/server.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::runtime::{new_engines, Engine, ProgramMeta, PROGRAM_TYPE_HTTP, PROGRAM_TYPE_WASI};
use crate::utils::generate_random_string;
use crate::{
DeleteRequest, ListResponse, LogRequest, LogResponse, Program, RestartRequest, RunRequest, ServeRequest,
StopRequest, Wacker, WackerServer, PROGRAM_STATUS_ERROR, PROGRAM_STATUS_FINISHED, PROGRAM_STATUS_RUNNING,
PROGRAM_STATUS_STOPPED,
DeleteRequest, ListResponse, LogRequest, LogResponse, Program, ProgramResponse, RestartRequest, RunRequest,
ServeRequest, StopRequest, Wacker, WackerServer, PROGRAM_STATUS_ERROR, PROGRAM_STATUS_FINISHED,
PROGRAM_STATUS_RUNNING, PROGRAM_STATUS_STOPPED,
};
use ahash::AHashMap;
use anyhow::{anyhow, Error, Result};
Expand Down Expand Up @@ -130,12 +130,12 @@ impl Server {
Ok(())
}

async fn update_db_and_run(&self, id: String, meta: ProgramMeta) -> Result<Response<()>, Status> {
async fn update_db_and_run(&self, id: String, meta: ProgramMeta) -> Result<Response<ProgramResponse>, Status> {
match bincode::serialize(&meta) {
Ok(bytes) => {
self.db.insert(id.as_str(), bytes).map_err(to_status)?;
self.run_inner(id, meta).await.map_err(to_status)?;
Ok(Response::new(()))
self.run_inner(id.clone(), meta).await.map_err(to_status)?;
Ok(Response::new(ProgramResponse { id }))
}
Err(err) => Err(Status::internal(err.to_string())),
}
Expand All @@ -148,7 +148,7 @@ fn to_status<E: Display>(err: E) -> Status {

#[async_trait]
impl Wacker for Server {
async fn run(&self, request: Request<RunRequest>) -> Result<Response<()>, Status> {
async fn run(&self, request: Request<RunRequest>) -> Result<Response<ProgramResponse>, Status> {
let req = request.into_inner();

let file_path = Path::new(&req.path);
Expand All @@ -174,7 +174,7 @@ impl Wacker for Server {
.await
}

async fn serve(&self, request: Request<ServeRequest>) -> Result<Response<()>, Status> {
async fn serve(&self, request: Request<ServeRequest>) -> Result<Response<ProgramResponse>, Status> {
let req = request.into_inner();

let file_path = Path::new(&req.path);
Expand Down

0 comments on commit fb707fc

Please sign in to comment.