Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(worker): add runner component #36

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ chrono = { version = "0.4", default-features = false, features = [
"serde",
] }
eyre = "0.6"
get-port = "4.0.0"
reqwest = { version = "0.12", features = ["json"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
Expand Down
24 changes: 12 additions & 12 deletions proto/src/worker/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@
//! service on a given worker node.

use serde::{Deserialize, Serialize};
use uuid::Uuid;

use crate::common::service::{ServiceName, ServiceSpec};
/// Specification of a service's instance
#[derive(Debug, Serialize, Deserialize)]
pub struct InstanceSpec {
id: Uuid,
image: String,
}

/// Starts a **single** deploy of the given service spec.
///
/// The worker server doesn't follow the concurrency limit for the service as
/// defined in [`ServiceSpec`].
#[derive(Debug, Serialize, Deserialize)]
pub struct DeployReq {
pub service_spec: ServiceSpec,
}

/// Response for [`DeployReq`].
/// defined in [`InstanceSpec`].
#[derive(Debug, Serialize, Deserialize)]
pub struct DeployRes {
// ???
pub struct DeployInstanceReq {
pub instances: Vec<InstanceSpec>,
}

/// Stops a given service from running in the system.
/// Stops a given instance from running in the system.
#[derive(Debug, Serialize, Deserialize)]
pub struct StopReq {
pub service_name: ServiceName,
pub instance: InstanceSpec,
/// Whether to completely remove the service from the node, calling the
/// teardown script, if any.
pub remove: bool,
Expand Down
1 change: 1 addition & 0 deletions worker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ proto.workspace = true

clap.workspace = true
eyre.workspace = true
get-port.workspace = true
reqwest.workspace = true
sysinfo.workspace = true
tokio.workspace = true
Expand Down
1 change: 1 addition & 0 deletions worker/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::{args::WorkerArgs, monitor::pusher};

mod args;
mod monitor;
mod runner;

#[tokio::main]
async fn main() -> Result<()> {
Expand Down
1 change: 1 addition & 0 deletions worker/src/runner/builder.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

24 changes: 24 additions & 0 deletions worker/src/runner/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use std::collections::HashMap;

use proto::worker::runner;

use get_port::{tcp::TcpPort, Range};

pub struct UsedPorts {
pub in_use: HashMap<uuid::Uuid,
}

pub fn deploy(instanceReq: &runner::DeployInstanceReq) -> Result<()> {
let tcp_port = TcpPort::in_range(
"127.0.0.1",
Range {
min: 6000,
max: 7000,
},
)
.unwrap();

Ok(())
}

pub fn terminate(instance: &InstanceSpec) {}