Skip to content

Commit

Permalink
build log: use async with
Browse files Browse the repository at this point in the history
Signed-off-by: Karol Swiderski <szakalboss@gmail.com>
  • Loading branch information
szakalboss committed May 27, 2021
1 parent c686374 commit 93dfa56
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions molior/molior/queues.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,17 @@ async def buildlog_writer(build_id):
del buildlogs[build_id]
return
try:
afp = AIOFile(filename, 'a')
await afp.open()
writer = Writer(afp)
while True:
msg = await dequeue(buildlogs[build_id])
if msg is None:
await enqueue_backend({"logging_done": build_id})
continue
elif msg is False:
break
await writer(msg)
await afp.fsync()
async with AIOFile(filename, 'a') as afp:
writer = Writer(afp)
while True:
msg = await dequeue(buildlogs[build_id])
if msg is None:
await enqueue_backend({"logging_done": build_id})
continue
elif msg is False:
break
await writer(msg)
await afp.fsync()
except Exception as exc:
logger.exception(exc)

Expand Down

0 comments on commit 93dfa56

Please sign in to comment.