pub mod client;
pub mod lifecycle;
pub mod port;
pub mod session;
pub mod spot;
pub use client::{ForgeClient, MetricsReport, start_heartbeat};
pub use lifecycle::{graceful_shutdown, is_ready, notify_shutdown, ready, shutdown_requested, shutdown_signal};
pub use port::{
allocate_port, allocate_specific_port, allocated_ports, is_port_available, release_port,
allocate_udp_port, allocate_specific_udp_port, allocate_game_port, allocate_specific_game_port,
allocate_port_with_protocol, allocate_specific_port_with_protocol,
allocated_ports_detailed, is_udp_port_available, is_port_available_for_protocol,
AllocatedPort, PortAllocator, Protocol,
};
pub use spot::{
SpotHandler, SpotInterruption, SpotAction, CloudProvider,
start_spot_monitor, wait_for_spot_interruption, is_spot_instance,
};
pub use session::{
Session, SessionId, SessionState, SessionTracker, SessionConfig,
ConnectionInfo,
};
use crate::error::ForgeError;
pub const FORGE_API_ENV: &str = "FORGE_API";
pub const FORGE_ALLOC_ID_ENV: &str = "FORGE_ALLOC_ID";
pub const FORGE_TASK_NAME_ENV: &str = "FORGE_TASK_NAME";
pub fn forge_api_url() -> Option<String> {
std::env::var(FORGE_API_ENV).ok()
}
pub fn alloc_id() -> Option<String> {
std::env::var(FORGE_ALLOC_ID_ENV).ok()
}
pub fn task_name() -> Option<String> {
std::env::var(FORGE_TASK_NAME_ENV).ok()
}
#[derive(Debug, thiserror::Error)]
pub enum SdkError {
#[error("Forge API not configured: set {0} environment variable")]
NotConfigured(&'static str),
#[error("API error: {0}")]
Api(String),
#[error("Port allocation failed: {0}")]
PortAllocation(String),
#[error("Lifecycle error: {0}")]
Lifecycle(String),
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
#[error("Serialization error: {0}")]
Serialization(#[from] serde_json::Error),
#[error("HTTP error: {0}")]
Http(#[from] reqwest::Error),
}
impl SdkError {
pub fn api(msg: impl Into<String>) -> Self {
Self::Api(msg.into())
}
pub fn port(msg: impl Into<String>) -> Self {
Self::PortAllocation(msg.into())
}
pub fn lifecycle(msg: impl Into<String>) -> Self {
Self::Lifecycle(msg.into())
}
}
impl From<SdkError> for ForgeError {
fn from(err: SdkError) -> Self {
ForgeError::Internal(err.to_string())
}
}
pub type SdkResult<T> = std::result::Result<T, SdkError>;