Skip to content

Commit

Permalink
wellenvogel#324 flush queue if messages get too old
Browse files Browse the repository at this point in the history
- no looping
- force an empty queue
  • Loading branch information
quantenschaum committed Feb 19, 2024
1 parent cf22518 commit cdb7470
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions server/handler/feeder.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
# parts from this software (AIS decoding) are taken from the gpsd project
# so refer to this BSD licencse also (see ais.py) or omit ais.py
###############################################################################
import time

from avnav_worker import *
hasSerial=False
Expand Down Expand Up @@ -216,15 +217,13 @@ def fetchFromHistory(self,sequence,maxEntries=10,
#our requested sequence is not in the list any more
numErrors=startSequence-sequence
startPoint=0
allowedAge=time.monotonic()-maxAge #maybe better related to return point
while self.history[startPoint].timestamp < allowedAge and startPoint < len(self.history):
numErrors+=1
startPoint+=1
min_time=time.monotonic()-maxAge # min required timestamp
if self.history[startPoint].timestamp < min_time: # data is too old
new_start=max(0,len(self.history)-maxEntries) # flush the queue
numErrors+=new_start-startPoint # discard messages
startPoint=new_start # return newest maxEntries only
if startPoint < len(self.history):
#something to return
numrt=len(self.history)-startPoint
if numrt > maxEntries:
numrt=maxEntries
numrt=min(len(self.history)-startPoint,maxEntries)
seq=startSequence+startPoint+numrt-1
rtlist=self.history[startPoint:startPoint+numrt]
break
Expand Down

0 comments on commit cdb7470

Please sign in to comment.