mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-11-28 08:06:16 +00:00
fix: relax git auto-pull polling only once the webhook has delivered (#12532)
* fix: relax git auto-pull polling only once the webhook has delivered Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: keep a delivering webhook verified while its last pull failed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs: state the caller contract of the webhook verification writer Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: do not count a ref's first auto-pull as a missed webhook delivery Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore: update ee-repo-ref to 6c06d688fe435630e2827bc177f066d2646bb768 This commit updates the EE repository reference after PR #996 was merged in windmill-ee-private. Previous ee-repo-ref: 095ef5033bff64ed5b2d08c84bb0037b83449d88 New ee-repo-ref: 6c06d688fe435630e2827bc177f066d2646bb768 Automated by sync-ee-ref workflow. --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: windmill-internal-app[bot] <windmill-internal-app[bot]@users.noreply.github.com> Co-authored-by: Ruben Fiszel <ruben@windmill.dev>
This commit is contained in:
co-authored by
Claude Opus 5.5
windmill-internal-app[bot]
Ruben Fiszel
parent
c8d047905e
commit
d538f2adfa
+16
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n UPDATE workspace_settings\n SET git_sync = jsonb_set(\n git_sync,\n '{repositories}',\n (SELECT jsonb_agg(\n CASE WHEN elem->>'git_repo_resource_path' = $2 AND elem ? 'auto_pull'\n THEN jsonb_set(elem, '{auto_pull,webhook_verified_id}',\n COALESCE(to_jsonb($3::bigint), 'null'::jsonb), true)\n ELSE elem END)\n FROM jsonb_array_elements(git_sync->'repositories') AS elem)\n )\n WHERE workspace_id = $1\n AND jsonb_typeof(git_sync->'repositories') = 'array'\n AND jsonb_array_length(git_sync->'repositories') > 0\n ",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text",
|
||||
"Text",
|
||||
"Int8"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "2f97623f4c3d5fdf4fc741058ef1fadee66ac151e7cdbdd8601e6bab3c5bf12e"
|
||||
}
|
||||
@@ -1 +1 @@
|
||||
d01848c5a62d19896cf5c67dd0b69582e5365be9
|
||||
6c06d688fe435630e2827bc177f066d2646bb768
|
||||
|
||||
+43
-6
@@ -5374,7 +5374,7 @@ async fn poll_git_auto_pull_inner(db: &Pool<Postgres>) -> error::Result<()> {
|
||||
Ok(Some((git_ref, sha))) => {
|
||||
// Shared reconcile (also used by the webhook receiver):
|
||||
// checks should_pull, enqueues, and records status/failure.
|
||||
if let Err(e) = windmill_git_sync::reconcile_and_enqueue_pull(
|
||||
match windmill_git_sync::reconcile_and_enqueue_pull(
|
||||
db,
|
||||
&row.workspace_id,
|
||||
repo,
|
||||
@@ -5384,11 +5384,48 @@ async fn poll_git_auto_pull_inner(db: &Pool<Postgres>) -> error::Result<()> {
|
||||
)
|
||||
.await
|
||||
{
|
||||
tracing::warn!(
|
||||
"git auto-pull: reconcile failed for {}/{}: {e:#}",
|
||||
row.workspace_id,
|
||||
repo.git_repo_resource_path
|
||||
);
|
||||
// The webhook should have brought this head already: it stopped
|
||||
// reaching us, so poll every minute again until it delivers. Not for
|
||||
// a ref's first sync, which no delivery could have brought, nor after
|
||||
// a failed pull: its rollback re-offers a head the webhook did deliver,
|
||||
// and demoting would retry the failing pull every minute.
|
||||
Ok(Some(_))
|
||||
if auto_pull.webhook_verified()
|
||||
&& auto_pull.last_synced_sha.contains_key(&git_ref)
|
||||
&& auto_pull
|
||||
.last_pull_status
|
||||
.as_ref()
|
||||
.map_or(true, |s| s.success) =>
|
||||
{
|
||||
tracing::warn!(
|
||||
"git auto-pull: {}/{} moved without a webhook delivery, polling every minute until one arrives",
|
||||
row.workspace_id,
|
||||
repo.git_repo_resource_path
|
||||
);
|
||||
if let Err(e) =
|
||||
windmill_common::workspaces::set_auto_pull_webhook_verified_id(
|
||||
db,
|
||||
&row.workspace_id,
|
||||
&repo.git_repo_resource_path,
|
||||
None,
|
||||
)
|
||||
.await
|
||||
{
|
||||
tracing::warn!(
|
||||
"git auto-pull: could not record the missed delivery for {}/{}: {e:#}",
|
||||
row.workspace_id,
|
||||
repo.git_repo_resource_path
|
||||
);
|
||||
}
|
||||
}
|
||||
Ok(_) => {}
|
||||
Err(e) => {
|
||||
tracing::warn!(
|
||||
"git auto-pull: reconcile failed for {}/{}: {e:#}",
|
||||
row.workspace_id,
|
||||
repo.git_repo_resource_path
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Parent-managed fork sync: list the fork branches' heads in
|
||||
|
||||
@@ -1022,6 +1022,7 @@ fn sanitize_client_auto_pull(
|
||||
auto_pull.webhook_secret = None;
|
||||
auto_pull.webhook_url = None;
|
||||
auto_pull.webhook_error = None;
|
||||
auto_pull.webhook_verified_id = None;
|
||||
auto_pull.last_synced_sha = std::collections::HashMap::new();
|
||||
auto_pull.last_pull_status = None;
|
||||
auto_pull.enabled_by = auto_pull.enabled.then(|| saver_email.to_string());
|
||||
@@ -5456,6 +5457,7 @@ async fn edit_git_sync_config(
|
||||
new_ap.webhook_id = old_ap.webhook_id;
|
||||
new_ap.webhook_secret = old_ap.webhook_secret.clone();
|
||||
new_ap.webhook_url = old_ap.webhook_url.clone();
|
||||
new_ap.webhook_verified_id = old_ap.webhook_verified_id;
|
||||
new_ap.last_synced_sha = old_ap.last_synced_sha.clone();
|
||||
new_ap.last_pull_status = old_ap.last_pull_status.clone();
|
||||
}
|
||||
@@ -5714,6 +5716,7 @@ async fn edit_git_sync_repository(
|
||||
new_ap.webhook_id = old_ap.webhook_id;
|
||||
new_ap.webhook_secret = old_ap.webhook_secret.clone();
|
||||
new_ap.webhook_url = old_ap.webhook_url.clone();
|
||||
new_ap.webhook_verified_id = old_ap.webhook_verified_id;
|
||||
}
|
||||
// UI omitted auto_pull (e.g. older client): keep existing config.
|
||||
(None, Some(_)) => {
|
||||
|
||||
@@ -40128,6 +40128,10 @@ components:
|
||||
type: string
|
||||
webhook_error:
|
||||
type: string
|
||||
webhook_verified_id:
|
||||
type: integer
|
||||
format: int64
|
||||
description: The webhook_id a delivery from the host last arrived for. Polling relaxes to about every 10 minutes only while it matches webhook_id. Set by the server.
|
||||
last_synced_sha:
|
||||
type: object
|
||||
additionalProperties:
|
||||
|
||||
@@ -106,6 +106,7 @@ pub(crate) fn redact_git_sync(git_sync: Option<Value>) -> Option<Value> {
|
||||
"webhook_secret",
|
||||
"webhook_id",
|
||||
"webhook_error",
|
||||
"webhook_verified_id",
|
||||
"last_synced_sha",
|
||||
"last_pull_status",
|
||||
"enabled_by",
|
||||
|
||||
@@ -561,6 +561,12 @@ pub struct AutoPullSettings {
|
||||
/// webhook is live or the repo is polling-only.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub webhook_error: Option<String>,
|
||||
/// The `webhook_id` a delivery from the host last arrived for. Creating a hook
|
||||
/// only proves Windmill reaches the host, not the reverse, so polling relaxes
|
||||
/// only once this matches `webhook_id`; a poll finding a head no delivery
|
||||
/// brought clears it.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub webhook_verified_id: Option<i64>,
|
||||
/// Last synced commit sha per tracked git ref (e.g. `refs/heads/main`).
|
||||
#[serde(default, skip_serializing_if = "std::collections::HashMap::is_empty")]
|
||||
pub last_synced_sha: std::collections::HashMap<String, String>,
|
||||
@@ -589,6 +595,7 @@ impl std::fmt::Debug for AutoPullSettings {
|
||||
)
|
||||
.field("webhook_url", &self.webhook_url)
|
||||
.field("webhook_error", &self.webhook_error)
|
||||
.field("webhook_verified_id", &self.webhook_verified_id)
|
||||
.field("last_synced_sha", &self.last_synced_sha)
|
||||
.field("last_pull_status", &self.last_pull_status)
|
||||
.finish()
|
||||
@@ -602,11 +609,16 @@ pub const DEFAULT_AUTO_PULL_POLL_INTERVAL_S: u32 = 60;
|
||||
pub const WEBHOOK_AUTO_PULL_POLL_INTERVAL_S: u32 = 600;
|
||||
|
||||
impl AutoPullSettings {
|
||||
/// Whether the registered hook has been seen delivering to this instance.
|
||||
pub fn webhook_verified(&self) -> bool {
|
||||
self.webhook_id.is_some() && self.webhook_verified_id == self.webhook_id
|
||||
}
|
||||
|
||||
/// Effective polling interval in seconds, honouring the explicit override and
|
||||
/// relaxing to `WEBHOOK_AUTO_PULL_POLL_INTERVAL_S` when a webhook is live.
|
||||
/// relaxing to `WEBHOOK_AUTO_PULL_POLL_INTERVAL_S` once the webhook delivers.
|
||||
pub fn effective_poll_interval_s(&self) -> u32 {
|
||||
self.poll_interval_s.unwrap_or_else(|| {
|
||||
if self.webhook_id.is_some() {
|
||||
if self.webhook_verified() {
|
||||
WEBHOOK_AUTO_PULL_POLL_INTERVAL_S
|
||||
} else {
|
||||
DEFAULT_AUTO_PULL_POLL_INTERVAL_S
|
||||
@@ -627,6 +639,44 @@ impl AutoPullSettings {
|
||||
}
|
||||
}
|
||||
|
||||
/// Record the hook a delivery arrived for (`Some`), or that a poll found a head no
|
||||
/// delivery brought (`None`), on one repository of `workspace_settings.git_sync`
|
||||
/// without touching the rest of it. Authorizes nothing: callers pass a workspace
|
||||
/// and repository they resolved themselves, the receiver only after verifying the
|
||||
/// delivery against that repository's own secret, never ids taken from a request.
|
||||
pub async fn set_auto_pull_webhook_verified_id(
|
||||
db: &crate::DB,
|
||||
w_id: &str,
|
||||
repo_resource_path: &str,
|
||||
hook_id: Option<i64>,
|
||||
) -> Result<()> {
|
||||
// COALESCE: `jsonb_set` with a NULL value returns NULL, which would wipe git_sync.
|
||||
sqlx::query!(
|
||||
r#"
|
||||
UPDATE workspace_settings
|
||||
SET git_sync = jsonb_set(
|
||||
git_sync,
|
||||
'{repositories}',
|
||||
(SELECT jsonb_agg(
|
||||
CASE WHEN elem->>'git_repo_resource_path' = $2 AND elem ? 'auto_pull'
|
||||
THEN jsonb_set(elem, '{auto_pull,webhook_verified_id}',
|
||||
COALESCE(to_jsonb($3::bigint), 'null'::jsonb), true)
|
||||
ELSE elem END)
|
||||
FROM jsonb_array_elements(git_sync->'repositories') AS elem)
|
||||
)
|
||||
WHERE workspace_id = $1
|
||||
AND jsonb_typeof(git_sync->'repositories') = 'array'
|
||||
AND jsonb_array_length(git_sync->'repositories') > 0
|
||||
"#,
|
||||
w_id,
|
||||
repo_resource_path,
|
||||
hook_id,
|
||||
)
|
||||
.execute(db)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct GitSyncSettings {
|
||||
pub include_path: Vec<String>,
|
||||
@@ -4226,6 +4276,7 @@ mod tests {
|
||||
webhook_secret: None,
|
||||
webhook_url: None,
|
||||
webhook_error: None,
|
||||
webhook_verified_id: None,
|
||||
enabled_by: None,
|
||||
last_synced_sha: synced
|
||||
.iter()
|
||||
@@ -4262,9 +4313,21 @@ mod tests {
|
||||
// explicit override wins
|
||||
s.poll_interval_s = Some(15);
|
||||
assert_eq!(s.effective_poll_interval_s(), 15);
|
||||
// with a live webhook and no override, relax to the webhook interval
|
||||
// a registered hook nothing has delivered from keeps polling every minute
|
||||
s.poll_interval_s = None;
|
||||
s.webhook_id = Some(42);
|
||||
assert_eq!(
|
||||
s.effective_poll_interval_s(),
|
||||
DEFAULT_AUTO_PULL_POLL_INTERVAL_S
|
||||
);
|
||||
// a delivery for an older hook does not count for its replacement
|
||||
s.webhook_verified_id = Some(41);
|
||||
assert_eq!(
|
||||
s.effective_poll_interval_s(),
|
||||
DEFAULT_AUTO_PULL_POLL_INTERVAL_S
|
||||
);
|
||||
// once it delivers, relax to the webhook interval
|
||||
s.webhook_verified_id = Some(42);
|
||||
assert_eq!(
|
||||
s.effective_poll_interval_s(),
|
||||
WEBHOOK_AUTO_PULL_POLL_INTERVAL_S
|
||||
|
||||
@@ -957,7 +957,13 @@
|
||||
</div>
|
||||
{/if}
|
||||
{#if repo.auto_pull?.enabled}
|
||||
{@const viaWebhook = repo.auto_pull?.webhook_id != null}
|
||||
{@const hookId = repo.auto_pull?.webhook_id}
|
||||
{@const viaWebhook =
|
||||
hookId != null && repo.auto_pull?.webhook_verified_id === hookId}
|
||||
{@const pollNote =
|
||||
hookId != null
|
||||
? ' Checking the tracked branch about every minute until the webhook delivers to this instance.'
|
||||
: ' Checking the tracked branch about every minute.'}
|
||||
{#if hasManagedCredential}
|
||||
<div class="mt-2">
|
||||
<Alert type="info" title="Already pulling with a CI job?" size="xs">
|
||||
@@ -976,9 +982,7 @@
|
||||
date={pullStatusDate(repo.auto_pull.last_pull_status)}
|
||||
noSeconds
|
||||
/>.
|
||||
{viaWebhook
|
||||
? ' Syncing instantly via webhook.'
|
||||
: ' Checking the tracked branch about every minute.'}
|
||||
{viaWebhook ? ' Syncing instantly via webhook.' : pollNote}
|
||||
{:else}
|
||||
<span class="text-red-600 dark:text-red-400">
|
||||
Last sync failed
|
||||
@@ -993,7 +997,7 @@
|
||||
{:else}
|
||||
{viaWebhook
|
||||
? 'Connected via webhook. New commits to the tracked branch deploy instantly.'
|
||||
: 'Checking the tracked branch about every minute. New commits deploy automatically.'}
|
||||
: `${pollNote.trim()} New commits deploy automatically.`}
|
||||
{/if}
|
||||
</div>
|
||||
{#if repo.auto_pull?.enabled_by}
|
||||
|
||||
Reference in New Issue
Block a user