Skip to content

Commit

Permalink
Handle only the latest event with the most up to date state
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Vasilyev committed Apr 26, 2019
1 parent 96c2787 commit 5a0b2da
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions kopf/reactor/queueing.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,17 @@ async def worker(

# Try ASAP, but give it few seconds for the new events to arrive, maybe.
# If the queue is empty for some time, then indeed finish the object's worker.
# If the queue is filled, use the latest event only (within the short timeframe).
try:
event = await asyncio.wait_for(queue.get(), timeout=5.0)
except asyncio.TimeoutError:
break
else:
try:
while True:
event = await asyncio.wait_for(queue.get(), timeout=0.1)
except asyncio.TimeoutError:
pass

# Try the handler. In case of errors, show the error, but continue the queue processing.
try:
Expand Down

0 comments on commit 5a0b2da

Please sign in to comment.