feat(subscribe): --prune flag removes all stale webhooks first
All checks were successful
Deploy Max Bot Test / deploy (push) Successful in 12s

Pipeline uses --prune so old tuna/test subscriptions don't linger after deploy.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
pkirillw
2026-06-18 00:44:40 +03:00
parent 98144779ef
commit bd5304ec5e
2 changed files with 12 additions and 1 deletions

View File

@@ -65,7 +65,7 @@ jobs:
fi
ssh -i ~/.ssh/id_rsa -p ${{ vars.SERVER_PORT }} ${{ vars.SERVER_USER }}@${{ vars.SERVER_HOST }} "
cd /home/pkirillw/dockered-services/max-bot-test && \
docker compose exec -T app bin/console webhook:subscribe"
docker compose exec -T app bin/console webhook:subscribe --prune"
- name: Health check
run: |

View File

@@ -20,6 +20,7 @@ final class SubscribeWebhookCommand extends AbstractCommand
$this->addOption('url', 'u', InputOption::VALUE_OPTIONAL, 'Override WEBHOOK_URL from env');
$this->addOption('secret', 's', InputOption::VALUE_OPTIONAL, 'Override MAX_BOT_API_SECRET from env');
$this->addOption('types', 't', InputOption::VALUE_OPTIONAL, 'Comma-separated update types (default: empty = all)');
$this->addOption('prune', null, InputOption::VALUE_NONE, 'Unsubscribe every other webhook before subscribing');
}
protected function doExecute(SymfonyStyle $io, InputInterface $input, OutputInterface $output): int
@@ -39,6 +40,16 @@ final class SubscribeWebhookCommand extends AbstractCommand
return self::FAILURE;
}
if ($input->getOption('prune')) {
$existing = $this->api->subscriptions->getSubscriptions();
foreach ($existing->subscriptions as $s) {
if ($s->url !== $url) {
$io->text("Pruning stale webhook: $s->url");
$this->api->subscriptions->unsubscribe($s->url);
}
}
}
$io->text("Subscribing $url with " . ($types === [] ? 'all update types' : 'types: ' . implode(',', $types)));
$result = $this->api->subscriptions->subscribe($url, $types, $secret);
if (!$result->success) {