Memory-queue ids carry a per-instance boot token, so a restart without Redis no longer overwrites earlier run rows

This commit is contained in:
2026-10-14 23:33:25 +02:00
parent 2ac997ce37
commit 245e68449f
2 changed files with 17 additions and 1 deletions
+5 -1
View File
@@ -18,6 +18,7 @@ from __future__ import annotations
import heapq
import logging
import secrets
import threading
import time
from abc import ABC, abstractmethod
@@ -272,12 +273,15 @@ class MemoryWorkQueue(WorkQueue):
self._in_flight = 0
self._counter = 0
self._seq = 0
# The ids become `FlowRun.id`, a primary key. Counting from zero alone,
# a restart would overwrite the previous boot's rows.
self._boot = secrets.token_hex(4)
self._lock = threading.Lock()
self._wake = threading.Condition(self._lock)
def _next_id(self) -> str:
self._seq += 1
return f"mem-{self._seq}"
return f"mem-{self._boot}-{self._seq}"
def add(self, item: WorkItem) -> None:
with self._wake: