1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#![warn(clippy::all, clippy::pedantic, clippy::nursery)]

use anyhow::Result;
use tracing_subscriber::{
	prelude::__tracing_subscriber_SubscriberExt, util::SubscriberInitExt, EnvFilter, Layer,
};

pub use spec::{Cog, CogResponse};

mod errors;
mod helpers;
mod prediction;
mod routes;
mod runner;
mod server;
mod shutdown;
mod spec;
mod webhooks;

/// Start the server with the given cog.
///
/// # Errors
///
/// This function will return an error if the PORT environment variable is set but cannot be parsed, or if the server fails to start.
pub async fn start<T: Cog + 'static>() -> Result<()> {
	tracing_subscriber::registry()
		.with(tracing_subscriber::fmt::layer().with_filter(
			EnvFilter::try_from_default_env().unwrap_or_else(|_| "cog_rust=info".into()),
		))
		.init();

	server::start::<T>().await
}

#[macro_export]
macro_rules! start {
	($struct_name:ident) => {
		#[tokio::main]
		async fn main() {
			cog_rust::start::<$struct_name>().await.unwrap();
		}
	};
}