queue the build of a config head that moved without a webhook build
This commit is contained in:
parent
a0c8892b99
commit
b7d8c0dfc0
1 changed files with 689 additions and 28 deletions
|
|
@ -17,9 +17,10 @@
|
|||
//!
|
||||
//! [`merged`] reads the same delivery for a merge, which the webhook handler
|
||||
//! turns into a deploy, and [`changed_head`] reads it for a PR's new head,
|
||||
//! which the handler turns into a build check (`crate::builder`). The poll
|
||||
//! has no counterpart to either: a merge whose delivery is lost deploys
|
||||
//! nothing, and a head whose delivery is lost is not built.
|
||||
//! which the handler turns into a build check (`crate::builder`). The cache
|
||||
//! poll has no counterpart to either, and a PR head whose delivery is lost is
|
||||
//! not built. A merge whose delivery is lost is deployed by
|
||||
//! [`crate::config_drift`], which [`spawn`] runs after each scan.
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
|
@ -267,29 +268,39 @@ impl ConfigPrCache {
|
|||
/// The scan runs immediately on the first tick (`tokio::time::interval`'s
|
||||
/// default), so the cache is populated on startup rather than staying empty
|
||||
/// for a full `POLL_INTERVAL` after boot.
|
||||
pub fn spawn(client: Arc<Client>) -> Arc<ConfigPrCache> {
|
||||
///
|
||||
/// With `drift`, each tick also runs [`crate::config_drift::run`] after the scan.
|
||||
pub(crate) fn spawn(
|
||||
client: Arc<Client>,
|
||||
drift: Option<crate::config_drift::Deps>,
|
||||
) -> Arc<ConfigPrCache> {
|
||||
let cache = Arc::new(ConfigPrCache::new());
|
||||
let cache_for_task = Arc::clone(&cache);
|
||||
tokio::spawn(async move {
|
||||
let mut ticker = tokio::time::interval(POLL_INTERVAL);
|
||||
loop {
|
||||
ticker.tick().await;
|
||||
let Some(scan) = crate::forge::within_forge_deadline(
|
||||
match crate::forge::within_forge_deadline(
|
||||
"config-pr poll",
|
||||
client.list_open_config_prs(),
|
||||
)
|
||||
.await
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
match scan {
|
||||
Ok(scan) => cache_for_task.replace(scan),
|
||||
Err(e) => {
|
||||
{
|
||||
Some(Ok(scan)) => cache_for_task.replace(scan),
|
||||
Some(Err(e)) => {
|
||||
tracing::warn!(
|
||||
error = %format!("{e:#}"),
|
||||
"config-pr poll: scan failed, cache keeps its last value"
|
||||
);
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
if let Some(drift) = &drift {
|
||||
crate::forge::within_forge_deadline(
|
||||
"config drift pass",
|
||||
crate::config_drift::run(drift, &client),
|
||||
)
|
||||
.await;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue