Use typed paths in worker
This commit is contained in:
parent
88d9a1f818
commit
3d5a277234
5 changed files with 25 additions and 14 deletions
|
|
@ -195,10 +195,11 @@ impl ConfigFile {
|
|||
.servers
|
||||
.iter()
|
||||
.map(|(name, server)| {
|
||||
let mut url = server.url.clone();
|
||||
if !url.ends_with('/') {
|
||||
url.push('/');
|
||||
}
|
||||
let url = server
|
||||
.url
|
||||
.strip_suffix('/')
|
||||
.unwrap_or(&server.url)
|
||||
.to_string();
|
||||
let token = server.token.to_string();
|
||||
(name.to_string(), WorkerServerConfig { url, token })
|
||||
})
|
||||
|
|
@ -209,7 +210,7 @@ impl ConfigFile {
|
|||
// TODO Url functions
|
||||
#[derive(Clone)]
|
||||
pub struct WorkerServerConfig {
|
||||
/// Always ends with a `/`.
|
||||
/// Never ends with a `/`.
|
||||
pub url: String,
|
||||
pub token: String,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
mod recurring;
|
||||
mod util;
|
||||
mod web;
|
||||
pub mod web;
|
||||
mod workers;
|
||||
|
||||
use std::{
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
mod admin;
|
||||
mod api;
|
||||
pub mod api;
|
||||
mod commit;
|
||||
mod index;
|
||||
mod link;
|
||||
|
|
|
|||
|
|
@ -202,7 +202,7 @@ fn stream_response(repo: Arc<ThreadSafeRepository>, id: ObjectId) -> impl IntoRe
|
|||
#[derive(Deserialize, TypedPath)]
|
||||
#[typed_path("/api/worker/repo/:hash/tree.tar.gz")]
|
||||
pub struct PathApiWorkerRepoByHashTreeTarGz {
|
||||
hash: String,
|
||||
pub hash: String,
|
||||
}
|
||||
|
||||
pub async fn get_api_worker_repo_by_hash_tree_tar_gz(
|
||||
|
|
@ -227,7 +227,7 @@ pub async fn get_api_worker_repo_by_hash_tree_tar_gz(
|
|||
#[derive(Deserialize, TypedPath)]
|
||||
#[typed_path("/api/worker/bench_repo/:hash/tree.tar.gz")]
|
||||
pub struct PathApiWorkerBenchRepoByHashTreeTarGz {
|
||||
hash: String,
|
||||
pub hash: String,
|
||||
}
|
||||
|
||||
pub async fn get_api_worker_bench_repo_by_hash_tree_tar_gz(
|
||||
|
|
|
|||
|
|
@ -7,6 +7,10 @@ use tracing::{debug, warn};
|
|||
|
||||
use crate::{
|
||||
config::{Config, WorkerServerConfig},
|
||||
server::web::api::worker::{
|
||||
PathApiWorkerBenchRepoByHashTreeTarGz, PathApiWorkerRepoByHashTreeTarGz,
|
||||
PathApiWorkerStatus,
|
||||
},
|
||||
shared::{FinishedRun, ServerResponse, WorkerRequest, WorkerStatus},
|
||||
somehow,
|
||||
worker::tree,
|
||||
|
|
@ -47,7 +51,7 @@ impl Server {
|
|||
request_run: bool,
|
||||
submit_run: Option<FinishedRun>,
|
||||
) -> somehow::Result<ServerResponse> {
|
||||
let url = format!("{}api/worker/status", self.server_config.url);
|
||||
let url = format!("{}{}", self.server_config.url, PathApiWorkerStatus {});
|
||||
|
||||
let status = match &*self.current_run.lock().unwrap() {
|
||||
Some(run) if run.is_for_server(&self.name) => {
|
||||
|
|
@ -80,8 +84,11 @@ impl Server {
|
|||
|
||||
pub async fn download_repo(&self, hash: &str) -> somehow::Result<TempDir> {
|
||||
let url = format!(
|
||||
"{}api/worker/repo/{hash}/tree.tar.gz",
|
||||
self.server_config.url
|
||||
"{}{}",
|
||||
self.server_config.url,
|
||||
PathApiWorkerRepoByHashTreeTarGz {
|
||||
hash: hash.to_string()
|
||||
},
|
||||
);
|
||||
|
||||
let response = self
|
||||
|
|
@ -96,8 +103,11 @@ impl Server {
|
|||
|
||||
pub async fn download_bench_repo(&self, hash: &str) -> somehow::Result<TempDir> {
|
||||
let url = format!(
|
||||
"{}api/worker/bench_repo/{hash}/tree.tar.gz",
|
||||
self.server_config.url
|
||||
"{}{}",
|
||||
self.server_config.url,
|
||||
PathApiWorkerBenchRepoByHashTreeTarGz {
|
||||
hash: hash.to_string()
|
||||
},
|
||||
);
|
||||
|
||||
let response = self
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue