forge_notify: HIVE_FORGE_KEEP_SUBSCRIPTIONS=1 disables auto-unsubscribe
This commit is contained in:
parent
eb63c7ebb1
commit
717086b02d
1 changed files with 22 additions and 8 deletions
|
|
@ -81,13 +81,28 @@ pub async fn run(socket: PathBuf, is_manager: bool) {
|
||||||
// socket becoming available right at boot.
|
// socket becoming available right at boot.
|
||||||
interval.tick().await;
|
interval.tick().await;
|
||||||
|
|
||||||
|
// HIVE_FORGE_KEEP_SUBSCRIPTIONS=1 disables auto-unsubscribe for agents
|
||||||
|
// that intentionally consume the full repo notification firehose (e.g. triage).
|
||||||
|
let keep_subscriptions = std::env::var("HIVE_FORGE_KEEP_SUBSCRIPTIONS")
|
||||||
|
.map(|v| v == "1" || v.eq_ignore_ascii_case("true"))
|
||||||
|
.unwrap_or(false);
|
||||||
|
|
||||||
// Repos we have already unsubscribed this process lifetime. Persists
|
// Repos we have already unsubscribed this process lifetime. Persists
|
||||||
// across polls so we don't hammer DELETE on every cycle.
|
// across polls so we don't hammer DELETE on every cycle.
|
||||||
let mut unsubbed_repos: HashSet<String> = HashSet::new();
|
let mut unsubbed_repos: HashSet<String> = HashSet::new();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
interval.tick().await;
|
interval.tick().await;
|
||||||
poll_once(&client, &forge_url, &token, &socket, is_manager, &mut unsubbed_repos).await;
|
poll_once(
|
||||||
|
&client,
|
||||||
|
&forge_url,
|
||||||
|
&token,
|
||||||
|
&socket,
|
||||||
|
is_manager,
|
||||||
|
keep_subscriptions,
|
||||||
|
&mut unsubbed_repos,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -233,6 +248,7 @@ async fn poll_once(
|
||||||
token: &str,
|
token: &str,
|
||||||
socket: &Path,
|
socket: &Path,
|
||||||
is_manager: bool,
|
is_manager: bool,
|
||||||
|
keep_subscriptions: bool,
|
||||||
unsubbed_repos: &mut HashSet<String>,
|
unsubbed_repos: &mut HashSet<String>,
|
||||||
) {
|
) {
|
||||||
let url = format!("{forge_url}/api/v1/notifications?all=false&limit=50");
|
let url = format!("{forge_url}/api/v1/notifications?all=false&limit=50");
|
||||||
|
|
@ -323,14 +339,12 @@ async fn poll_once(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Auto-unsubscribe from broad repo watches. If the notification
|
// Auto-unsubscribe from broad repo watches when the notification
|
||||||
// reason is "subscribed" (agent is watching the whole repo) and
|
// reason is "subscribed" (agent watching the whole repo). Skipped
|
||||||
// the agent has no personal stake (was just watching), drop the
|
// when HIVE_FORGE_KEEP_SUBSCRIPTIONS=1 — triage and other firehose
|
||||||
// watch subscription so we don't accumulate firehose noise from
|
// consumers set this to retain broad repo visibility.
|
||||||
// repos we contributed to but are no longer actively working in.
|
|
||||||
// Thread-level subscriptions (specific issue/PR) are unaffected.
|
|
||||||
let reason = notif["reason"].as_str().unwrap_or("");
|
let reason = notif["reason"].as_str().unwrap_or("");
|
||||||
if reason == "subscribed" {
|
if !keep_subscriptions && reason == "subscribed" {
|
||||||
if let Some(repo) = notif["repository"]["full_name"].as_str() {
|
if let Some(repo) = notif["repository"]["full_name"].as_str() {
|
||||||
if !unsubbed_repos.contains(repo) {
|
if !unsubbed_repos.contains(repo) {
|
||||||
let unsub_url = format!("{forge_url}/api/v1/repos/{repo}/subscription");
|
let unsub_url = format!("{forge_url}/api/v1/repos/{repo}/subscription");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue