Skip to content

Commit 67bd638

Browse files
authored
Catch kombu.exceptions.OperationalError exception. (#234)
1 parent df3dd90 commit 67bd638

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

miss_islington/backport_pr.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import random
44

55
import gidgethub.routing
6-
import redis
6+
from kombu import exceptions as kombu_ex
7+
from redis import exceptions as redis_ex
78

89
from . import tasks, util
910

@@ -76,10 +77,10 @@ async def kickoff_backport_task(
7677
created_by=created_by,
7778
merged_by=merged_by,
7879
)
79-
except redis.exceptions.ConnectionError as ce:
80+
except (redis_ex.ConnectionError, kombu_ex.OperationalError) as ex:
8081
retry_num = retry_num + 1
8182
if retry_num < 5:
82-
err_message = f"I'm having trouble backporting to `{branch}`. Reason: '`{ce}`'. Will retry in 1 minute. Retry # {retry_num}"
83+
err_message = f"I'm having trouble backporting to `{branch}`. Reason: '`{ex}`'. Will retry in 1 minute. Retry # {retry_num}"
8384
await util.leave_comment(gh, issue_number, err_message)
8485
await asyncio.sleep(int(os.environ.get("RETRY_SLEEP_TIME", "60")))
8586
await kickoff_backport_task(

tests/test_backport_pr.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import os
22
from unittest import mock
33

4-
import redis
54
from gidgethub import sansio
65

6+
import redis
7+
import kombu
8+
79
os.environ["REDIS_URL"] = "someurl"
810
os.environ["RETRY_SLEEP_TIME"] = "1"
911

@@ -248,3 +250,36 @@ async def test_backport_pr_redis_connection_error():
248250
backport_delay_mock.side_effect = redis.exceptions.ConnectionError
249251
await backport_pr.router.dispatch(event, gh)
250252
assert "trouble backporting after 5 attempts" in gh.post_data["body"]
253+
254+
255+
async def test_backport_pr_kombu_operational_error():
256+
data = {
257+
"action": "closed",
258+
"pull_request": {
259+
"merged": True,
260+
"number": 1,
261+
"merged_by": {"login": "Mariatta"},
262+
"user": {"login": "gvanrossum"},
263+
"merge_commit_sha": "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9",
264+
},
265+
"repository": {
266+
"issues_url": "https://api.github.com/repos/python/cpython/issues/1"
267+
},
268+
}
269+
event = sansio.Event(data, event="pull_request", delivery_id="1")
270+
271+
getitem = {
272+
"https://api.github.com/repos/python/cpython/issues/1": {
273+
"labels_url": "https://api.github.com/repos/python/cpython/issues/1/labels{/name}"
274+
},
275+
"https://api.github.com/repos/python/cpython/issues/1/labels": [
276+
{"name": "CLA signed"},
277+
{"name": "needs backport to 3.7"},
278+
],
279+
}
280+
281+
gh = FakeGH(getitem=getitem)
282+
with mock.patch("miss_islington.tasks.backport_task.delay") as backport_delay_mock:
283+
backport_delay_mock.side_effect = kombu.exceptions.OperationalError
284+
await backport_pr.router.dispatch(event, gh)
285+
assert "trouble backporting after 5 attempts" in gh.post_data["body"]

0 commit comments

Comments
 (0)