Skip to content

Commit d333c83

Browse files
authored
When logging error also log the callstack and in case async task fail cancel the rest of the tasks but continue execution. (#86)
1 parent b347e84 commit d333c83

File tree

5 files changed

+17
-25
lines changed

5 files changed

+17
-25
lines changed

libmozevent/bus.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ async def receive(self, name: str):
9898
try:
9999
return pickle.loads(payload)
100100
except Exception as e:
101-
logger.error("Bad redis payload", error=str(e))
101+
logger.error("Bad redis payload", error=str(e), exc_info=True)
102102
await asyncio.sleep(1)
103103
return
104104

libmozevent/mercurial.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,11 @@ def get_author(commit):
218218
user=user.encode("utf-8"),
219219
)
220220
except Exception as e:
221-
logger.error("Failed to apply patch: {}".format(e), phid=patch.phid)
221+
logger.error(
222+
"Failed to apply patch: {}".format(e),
223+
phid=patch.phid,
224+
exc_info=True,
225+
)
222226
raise
223227

224228
def add_try_commit(self, build):
@@ -338,7 +342,10 @@ async def run(self):
338342

339343
else:
340344
logger.error(
341-
"Unsupported repository", repo=build.repo_phid, build=build
345+
"Unsupported repository",
346+
repo=build.repo_phid,
347+
build=build,
348+
exc_info=True,
342349
)
343350

344351
def is_commit_skippable(self, build):
@@ -378,7 +385,8 @@ def get_status():
378385
while status := get_status() != "open":
379386
if (datetime.utcnow() - start).seconds >= TRY_STATUS_MAX_WAIT:
380387
logger.error(
381-
f"Try tree status still closed after {TRY_STATUS_MAX_WAIT} seconds, skipping"
388+
f"Try tree status still closed after {TRY_STATUS_MAX_WAIT} seconds, skipping",
389+
exc_info=True,
382390
)
383391
break
384392
logger.warning(

libmozevent/utils.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,10 @@ async def _run():
5151
try:
5252
await tasks_group
5353
except Exception as e:
54-
log.error("Failure while running async tasks", error=str(e))
54+
log.error("Failure while running async tasks", error=str(e), exc_info=True)
5555
# When ANY exception from one of the awaitables
5656
# make sure the other awaitables are cancelled
5757
tasks_group.cancel()
58-
raise e
5958

6059
try:
6160
event_loop.run_until_complete(_run())
@@ -101,7 +100,9 @@ def _log_process(output, name):
101100

102101
out, err = proc.communicate()
103102
if proc.returncode != 0:
104-
log.error("Mercurial {} failure".format(main_cmd), out=out, err=err)
103+
log.error(
104+
"Mercurial {} failure".format(main_cmd), out=out, err=err, exc_info=True
105+
)
105106
raise hglib.error.CommandError(cmd, proc.returncode, out, err)
106107

107108
return out

libmozevent/web.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ async def create_code_review(self, request):
7474
build = PhabricatorBuild(request)
7575
await self.bus.send(self.queue_name, build)
7676
except Exception as e:
77-
logger.error(str(e), path=request.path_qs)
77+
logger.error(str(e), path=request.path_qs, exc_info=True)
7878
raise web.HTTPBadRequest(text=str(e))
7979

8080
logger.info("Queued new build", build=str(build))

tests/test_utils.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -81,20 +81,3 @@ async def await_blpop(*args):
8181
message = pickle.dumps("message", protocol=pickle.HIGHEST_PROTOCOL)
8282

8383
assert redis_queue == [(queue_name, message)]
84-
85-
async def deadly_task():
86-
await bus.receive("input")
87-
# Ensure the message has been consumed
88-
assert redis_queue == []
89-
# Raise an unexpected error or send a TERM signal to itself
90-
task_side_effect()
91-
await asyncio.sleep(10)
92-
93-
with pytest.raises(expected_exception):
94-
utils.run_tasks([deadly_task()], bus_to_restore=bus)
95-
96-
if expected_exception == asyncio.CancelledError:
97-
# In case of a SIGTERM, the message has been restored in the queue
98-
assert redis_queue == [(queue_name, message)]
99-
else:
100-
assert redis_queue == []

0 commit comments

Comments
 (0)