Move "desynced" logic into a predicate
parent
3dd82c8d31
commit
53dedbd645
|
@ -269,21 +269,23 @@ async def cascade(
|
||||||
|
|
||||||
async for msg in stream:
|
async for msg in stream:
|
||||||
|
|
||||||
# respawn the compute task if the source
|
def desynced(src: ShmArray, dst: ShmArray) -> bool:
|
||||||
# array has been updated such that we compute
|
diff = src.index - dst.index
|
||||||
# new history from the (prepended) source.
|
len_diff = abs(len(src.array) - len(dst.array))
|
||||||
diff = src.index - dst.index
|
return (
|
||||||
|
# the source is likely backfilling and we must
|
||||||
|
# sync history calculations
|
||||||
|
len_diff > 2 or
|
||||||
|
|
||||||
# new_len = len(src.array)
|
# we aren't step synced to the source and may be
|
||||||
|
# leading/lagging by a step
|
||||||
|
diff > 1 or
|
||||||
|
diff < 0
|
||||||
|
)
|
||||||
|
|
||||||
async def poll_and_sync_to_step(tracker):
|
async def poll_and_sync_to_step(tracker):
|
||||||
diff = src.index - dst.index
|
while desynced(src, dst):
|
||||||
while True:
|
|
||||||
if diff in (0, 1):
|
|
||||||
break
|
|
||||||
|
|
||||||
tracker, index = await resync(tracker)
|
tracker, index = await resync(tracker)
|
||||||
diff = src.index - dst.index
|
|
||||||
# log.info(
|
# log.info(
|
||||||
# '\n'.join((
|
# '\n'.join((
|
||||||
# f'history index after sync: {index}',
|
# f'history index after sync: {index}',
|
||||||
|
@ -293,18 +295,10 @@ async def cascade(
|
||||||
|
|
||||||
return tracker, diff
|
return tracker, diff
|
||||||
|
|
||||||
# log.debug(f'diff {diff}')
|
# respawn the compute task if the source
|
||||||
|
# array has been updated such that we compute
|
||||||
if (
|
# new history from the (prepended) source.
|
||||||
# the source is likely backfilling and we must
|
if desynced(src, dst):
|
||||||
# sync history calculations
|
|
||||||
abs(len(src.array) - len(dst.array)) > 0 or
|
|
||||||
|
|
||||||
# we aren't step synced to the source and may be
|
|
||||||
# leading/lagging by a step
|
|
||||||
diff > 1 or
|
|
||||||
diff < 0
|
|
||||||
):
|
|
||||||
tracker, diff = await poll_and_sync_to_step(tracker)
|
tracker, diff = await poll_and_sync_to_step(tracker)
|
||||||
|
|
||||||
# skip adding a last bar since we should be
|
# skip adding a last bar since we should be
|
||||||
|
|
Loading…
Reference in New Issue