Expose git version for use from deployment pipeline.
This commit is contained in:
parent
28f4e38e4c
commit
a985279db3
5
Cargo.lock
generated
5
Cargo.lock
generated
@ -188,6 +188,7 @@ dependencies = [
|
||||
"blastmud_interfaces",
|
||||
"futures",
|
||||
"log",
|
||||
"once_cell",
|
||||
"rand",
|
||||
"serde",
|
||||
"serde_yaml",
|
||||
@ -1111,9 +1112,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.16.0"
|
||||
version = "1.17.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860"
|
||||
checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66"
|
||||
|
||||
[[package]]
|
||||
name = "ouroboros"
|
||||
|
9
blastmud_game/build.rs
Normal file
9
blastmud_game/build.rs
Normal file
@ -0,0 +1,9 @@
|
||||
use std::process::Command;
|
||||
|
||||
pub fn main() {
|
||||
let cmdout = Command::new("git")
|
||||
.arg("rev-parse").arg("HEAD")
|
||||
.output().expect("git rev-parse HEAD failed");
|
||||
println!("cargo:rustc-env=GIT_VERSION={}",
|
||||
String::from_utf8(cmdout.stdout).expect("git revision not UTF-8"));
|
||||
}
|
@ -212,9 +212,40 @@ fn start_task_runner(pool: db::DBPool) {
|
||||
});
|
||||
}
|
||||
|
||||
async fn send_version_once(listener_map: ListenerMap) -> DResult<()> {
|
||||
for listener_sender in listener_map.lock().await.values().cloned() {
|
||||
let (tx, rx) = oneshot::channel();
|
||||
listener_sender.send(
|
||||
ListenerSend {
|
||||
message: MessageToListener::GameserverVersion {
|
||||
version: env!("GIT_VERSION").to_owned()
|
||||
},
|
||||
ack_notify: tx
|
||||
}
|
||||
).await.unwrap_or(());
|
||||
rx.await.unwrap_or(());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn start_version_send_task(listener_map: ListenerMap) {
|
||||
task::spawn(async move {
|
||||
loop {
|
||||
time::sleep(time::Duration::from_millis(30000)).await;
|
||||
match send_version_once(listener_map.clone()).await {
|
||||
Ok(()) => {}
|
||||
Err(e) => {
|
||||
warn!("Error processing tasks: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
pub fn start_regular_tasks(pool: &db::DBPool, listener_map: ListenerMap) -> DResult<()> {
|
||||
start_session_cleanup_task(pool.clone());
|
||||
start_send_queue_task(pool.clone(), listener_map);
|
||||
start_send_queue_task(pool.clone(), listener_map.clone());
|
||||
start_version_send_task(listener_map);
|
||||
start_task_runner(pool.clone());
|
||||
Ok(())
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ pub enum MessageFromListener {
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub enum MessageToListener {
|
||||
GameserverVersion { version: String },
|
||||
DisconnectSession { session: Uuid },
|
||||
SendToSession { session: Uuid, msg: String },
|
||||
AcknowledgeMessage
|
||||
|
@ -9,6 +9,7 @@ edition = "2021"
|
||||
blastmud_interfaces = { path = "../blastmud_interfaces" }
|
||||
futures = "0.3.25"
|
||||
log = "0.4.17"
|
||||
once_cell = "1.17.0"
|
||||
rand = "0.8.5"
|
||||
serde = { version = "1.0.149", features = ["derive", "serde_derive"] }
|
||||
serde_yaml = "0.9.14"
|
||||
|
9
blastmud_listener/build.rs
Normal file
9
blastmud_listener/build.rs
Normal file
@ -0,0 +1,9 @@
|
||||
use std::process::Command;
|
||||
|
||||
pub fn main() {
|
||||
let cmdout = Command::new("git")
|
||||
.arg("rev-parse").arg("HEAD")
|
||||
.output().expect("git rev-parse HEAD failed");
|
||||
println!("cargo:rustc-env=GIT_VERSION={}",
|
||||
String::from_utf8(cmdout.stdout).expect("git revision not UTF-8"));
|
||||
}
|
@ -8,7 +8,7 @@ use tokio::task;
|
||||
use tokio::time::{self, Duration};
|
||||
use tokio::net::{TcpStream, TcpListener, lookup_host};
|
||||
use tokio::signal::unix::{signal, SignalKind};
|
||||
use tokio::sync::{mpsc, Mutex};
|
||||
use tokio::sync::{mpsc, Mutex, RwLock};
|
||||
use tokio::io::{BufReader, AsyncWriteExt};
|
||||
use log::{warn, info, LevelFilter};
|
||||
use simple_logger::SimpleLogger;
|
||||
@ -20,9 +20,9 @@ use tokio_serde::formats::Cbor;
|
||||
use futures::prelude::*;
|
||||
use uuid::Uuid;
|
||||
use tokio_stream::wrappers::ReceiverStream;
|
||||
use warp;
|
||||
use warp::filters::ws;
|
||||
use warp::Filter;
|
||||
use warp::{
|
||||
self, filters::ws, Filter, Reply
|
||||
};
|
||||
use std::time::Instant;
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
@ -159,7 +159,7 @@ where
|
||||
message_handler
|
||||
);
|
||||
break 'full_select;
|
||||
}
|
||||
}
|
||||
Ok(Some(MessageToListener::AcknowledgeMessage)) => {
|
||||
break 'wait_for_ack;
|
||||
}
|
||||
@ -238,6 +238,10 @@ type SessionMap = Arc<Mutex<SessionIndexes>>;
|
||||
async fn handle_server_message(session_map: SessionMap, message: MessageToListener) {
|
||||
match message {
|
||||
MessageToListener::AcknowledgeMessage => {}
|
||||
MessageToListener::GameserverVersion { version } => {
|
||||
let mut version_mut = version_data().write().await;
|
||||
(*version_mut).gameserver_version = Some(version.clone());
|
||||
},
|
||||
MessageToListener::DisconnectSession { session } => {
|
||||
match session_map.lock().await.by_uuid.get(&session) {
|
||||
// Just silently ignore it if they are disconnected.
|
||||
@ -584,14 +588,35 @@ async fn handle_websocket(
|
||||
async fn upgrade_websocket(src: String, wsreq: ws::Ws,
|
||||
active_sessions: SessionMap,
|
||||
server_sender: mpsc::Sender<ServerTaskCommand>) ->
|
||||
Result<impl warp::Reply, warp::Rejection> {
|
||||
Result<warp::reply::Response, warp::Rejection> {
|
||||
Ok(
|
||||
wsreq.on_upgrade(|wss| handle_websocket(
|
||||
wss, src, active_sessions,
|
||||
server_sender))
|
||||
server_sender)).into_response()
|
||||
)
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct VersionData {
|
||||
listener_version: String,
|
||||
gameserver_version: Option<String>,
|
||||
}
|
||||
|
||||
fn version_data() -> &'static Arc<RwLock<VersionData>> {
|
||||
static VERSION_DATA: once_cell::sync::OnceCell<Arc<RwLock<VersionData>>> =
|
||||
once_cell::sync::OnceCell::new();
|
||||
VERSION_DATA.get_or_init(|| {
|
||||
Arc::new(RwLock::new(VersionData {
|
||||
listener_version: env!("GIT_VERSION").to_owned(),
|
||||
gameserver_version: None,
|
||||
}))
|
||||
})
|
||||
}
|
||||
|
||||
async fn respond_version() -> Result<warp::reply::Response, warp::Rejection> {
|
||||
Ok(warp::reply::json(&*version_data().read().await).into_response())
|
||||
}
|
||||
|
||||
async fn start_websocket(bind: String, active_sessions: SessionMap, server_sender: mpsc::Sender<ServerTaskCommand>) -> DResult<()> {
|
||||
let sockaddr = lookup_host(bind).await?.next().expect("Can't resolve websocket bind name");
|
||||
let routes =
|
||||
@ -599,7 +624,10 @@ async fn start_websocket(bind: String, active_sessions: SessionMap, server_sende
|
||||
.and(warp::path("wsgame"))
|
||||
.and(warp::header("X-Forwarded-For"))
|
||||
.and(ws::ws())
|
||||
.and_then(move |src, wsreq| upgrade_websocket(src, wsreq, active_sessions.clone(), server_sender.clone()));
|
||||
.and_then(move |src, wsreq| upgrade_websocket(src, wsreq, active_sessions.clone(), server_sender.clone()))
|
||||
.or(warp::get()
|
||||
.and(warp::path("version"))
|
||||
.and_then(|| respond_version()));
|
||||
|
||||
task::spawn(
|
||||
warp::serve(
|
||||
|
Loading…
Reference in New Issue
Block a user