Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webhook: Retry OSError on queue connection failure #636

Merged
merged 2 commits into from
Dec 17, 2024
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
2 changes: 1 addition & 1 deletion tasks/cockpit-tasks-webhook.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ spec:
ports:
- containerPort: 8080
protocol: TCP
command: [ "sh", "-ec", "sleep 10; exec webhook" ]
command: [ "webhook" ]
volumeMounts:
- name: webhook-secrets
mountPath: /run/secrets/webhook
Expand Down
22 changes: 11 additions & 11 deletions tasks/container/webhook
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/python3

import os
import sys
import logging
import subprocess
import contextlib
import http.server
import json
import contextlib
import logging
import os
import ssl
import subprocess
import sys
import time

import pika
Expand All @@ -34,7 +34,7 @@ fi


def setup_home():
'''Prepare temporary home directory from secrets'''
"""Prepare temporary home directory from secrets"""

if os.path.isdir(HOME_DIR):
return
Expand Down Expand Up @@ -76,7 +76,7 @@ def distributed_queue(amqp_server):


def scan_tasks():
'''scan project PRs and issues to (re)build the tasks queue'''
"""scan project PRs and issues to (re)build the tasks queue"""

from lib import testmap
from task.distributed_queue import DEFAULT_AMQP_SERVER
Expand All @@ -88,8 +88,8 @@ def scan_tasks():
try:
with distributed_queue(AMQP_SERVER):
break
except pika.exceptions.AMQPError as e:
logging.info(f"Failed to connect to AMQP, attempt #{retry}: {e}")
except (OSError, pika.exceptions.AMQPError) as e:
logging.info("Failed to connect to AMQP, attempt #%i: %s", retry, e)
time.sleep(5)

for project in testmap.projects():
Expand Down Expand Up @@ -135,7 +135,7 @@ class CockpituousHandler(github_handler.GithubHandler):
logging.info("pull request was merged, ensuring cockpit checkout is latest main")
ensure_bots_checkout()
elif action not in ['opened', 'synchronize', 'edited', 'labeled']:
logging.info("action %s unknown, skipping pull request event" % action)
logging.info("action %s unknown, skipping pull request event", action)
return None

publish_to_queue('webhook', event, request)
Expand All @@ -160,7 +160,7 @@ class CockpituousHandler(github_handler.GithubHandler):
def handle_issues_event(self, event, request):
action = request['action']
if event == 'issues' and action not in ['edited', 'labeled']:
logging.info("action %s unknown, skipping issues event" % action)
logging.info("action %s unknown, skipping issues event", action)
return None

publish_to_queue('webhook', event, request)
Expand Down