Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions server/src/cron.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub const MATCHMAKER_INTERVAL_SECS: u64 = 15 * 60;
/// a broken snake is pulled from matchmaking after ~90 minutes.
pub const SNAKE_HEALTH_SWEEP_INTERVAL_SECS: u64 = 30 * 60;

fn cron_registry() -> CronRegistry<AppState> {
pub(crate) fn cron_registry() -> CronRegistry<AppState> {
let mut registry = CronRegistry::new();

// Game backup discovery: runs every hour, enqueues backup jobs for games from the last 4 hours
Expand Down Expand Up @@ -60,8 +60,11 @@ fn cron_registry() -> CronRegistry<AppState> {
registry
}

pub(crate) async fn run_cron(app_state: AppState) -> cja::Result<()> {
Ok(Worker::new(app_state, cron_registry())
pub(crate) async fn run_cron(
app_state: AppState,
registry: CronRegistry<AppState>,
) -> cja::Result<()> {
Ok(Worker::new(app_state, registry)
.run(CancellationToken::new())
.await?)
}
19 changes: 18 additions & 1 deletion server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,20 @@ async fn spawn_application_tasks(app_state: AppState) -> cja::Result<Vec<NamedTa
let features = app_state.config.features;
let job = &app_state.config.job;

// Build the cron registry once so we can both report it to Eyes and hand
// it to the cron worker. Built unconditionally so the boot manifest
// reflects the full deployed shape even when CRON is disabled for this
// process.
let cron_registry = cron::cron_registry();

// Emit the Eyes boot manifest describing this app's jobs and cron. This is
// a no-op unless EYES_ORG_ID/EYES_APP_ID are configured.
cja::eyes_manifest::send_boot_manifest::<jobs::Jobs, AppState>(
Some(env!("CARGO_PKG_VERSION")),
option_env!("VERGEN_GIT_SHA"),
Some(&cron_registry),
);

if features.server {
info!("Server Enabled");
tasks.push(NamedTask::spawn(
Expand Down Expand Up @@ -204,7 +218,10 @@ async fn spawn_application_tasks(app_state: AppState) -> cja::Result<Vec<NamedTa

if features.cron {
info!("Cron Enabled");
tasks.push(NamedTask::spawn("cron", cron::run_cron(app_state.clone())));
tasks.push(NamedTask::spawn(
"cron",
cron::run_cron(app_state.clone(), cron_registry),
));
} else {
info!("Cron Disabled");
}
Expand Down
Loading