Skip to content

Commit

Permalink
worker: write deploy-confs to file
Browse files Browse the repository at this point in the history
  • Loading branch information
Gitea committed Apr 1, 2024
1 parent 2b3ca17 commit 97f25b9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 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 land-worker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ land-worker-server = { workspace = true }
once_cell = { workspace = true }
reqwest = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
serde_yaml = "0.9.33"
tokio = { workspace = true }
tracing = { workspace = true }
Expand Down
13 changes: 9 additions & 4 deletions land-worker/src/agent/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use reqwest::header::AUTHORIZATION;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use tokio::sync::Mutex;
use tracing::{info, instrument, warn};
use tracing::{debug, info, instrument, warn};

#[derive(Debug, Serialize, Deserialize)]
pub struct Request {
Expand Down Expand Up @@ -39,9 +39,9 @@ pub async fn start(interval: u64, addr: String, token: String, dir: String) {
info!("Center addr:{}", addr);

// mkdir traefik yaml dir
let traefik_yaml_dir = format!("{}/traefik",dir);
let traefik_yaml_dir = format!("{}/traefik", dir);
std::fs::create_dir_all(traefik_yaml_dir).unwrap();

tokio::spawn(async move {
let mut ticker = tokio::time::interval(tokio::time::Duration::from_secs(interval));
loop {
Expand Down Expand Up @@ -80,10 +80,15 @@ async fn sync(addr: String, token: String, dir: String) -> Result<()> {
warn!("Bad status code: {}", status);
return Err(anyhow!("Bad status code: {}", status));
}
let value: Response = resp.json().await?;
let content = resp.text().await?;
let value: Response = serde_json::from_str(&content)?;
*data = value.data;
info!("Sync success, checksum: {}", data.checksum);

let confs_file = format!("{}/deploy-confs.json", dir);
debug!("Write to file: {}", confs_file);
std::fs::write(confs_file, content).unwrap();

tokio::spawn(async move {
super::deploys::build(dir).await;
});
Expand Down

0 comments on commit 97f25b9

Please sign in to comment.