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
28 changes: 28 additions & 0 deletions app/src/console/demo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//! `demo:reset`, daily: rebuild the public demo, visualci/demo, from scratch (`domain::demo`), undoing anything done to
//! it since. Pushes its result to `VISUALCI_DEMO_HEARTBEAT_URL` (and `_TOKEN`): Gatus alerts on a failed run and on a
//! day with no run.

use laravel::console::{Console, clap, command};

use super::heartbeat;
use crate::domain::demo;
use crate::storage::BlobStore;

#[derive(clap::Parser)]
#[command(name = "demo:reset")]
pub struct DemoReset;

#[command]
impl DemoReset {
async fn handle(self, console: &mut Console) -> laravel::Result<()> {
let result = async {
let store = BlobStore::current().await?;
Box::pin(demo::reset(&store, &crate::http::api::builds::renderer_version())).await
}
.await;
heartbeat::push("VISUALCI_DEMO_HEARTBEAT", result.as_ref().map(|_| ()).map_err(ToString::to_string)).await;
let builds = result?;
console.line(format!("demo reset: {}/{} has {builds} builds", demo::ORG, demo::PROJECT));
Ok(())
}
}
8 changes: 5 additions & 3 deletions app/src/console/mod.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
//! The schedule (`laravel schedule:run` every minute, in production a CronJob): the builds sweep every five minutes,
//! retention and the groups check daily, each run pushing its result to a heartbeat so a task that failed or stopped
//! running alerts.
//! The schedule (`laravel schedule:run` every minute, in production a CronJob): the builds sweep every five minutes;
//! retention, the groups check and the demo reset daily. Each run pushes its result to a heartbeat, so a task that
//! failed or stopped running alerts.

use laravel::schedule::{self, Schedule};

// The heartbeat every scheduled task pushes to (`crate::heartbeat`).
pub use crate::heartbeat;
pub mod demo;
pub mod retention;

#[schedule::tasks]
fn schedule(schedule: &mut Schedule) {
schedule.call(sweep_builds).name("builds-sweep").every_five_minutes().without_overlapping().on_one_runner();
schedule.command("retention:prune").daily_at("03:00").without_overlapping().on_one_runner();
schedule.command("groups:check").daily_at("04:00").without_overlapping().on_one_runner();
schedule.command("demo:reset").name("demo-reset").daily_at("05:00").without_overlapping().on_one_runner();
}

/// [`crate::domain::processing::sweep`], with its heartbeat (`VISUALCI_BUILDS_SWEEP_HEARTBEAT_URL` and `_TOKEN`).
Expand Down
Loading
Loading