phase 1
This commit is contained in:
@@ -17,19 +17,23 @@ def _get_redis():
|
||||
return redis.from_url(REDIS_URL, decode_responses=True)
|
||||
|
||||
|
||||
def push_event(job_id: str, event_type: str, data: dict) -> None:
|
||||
def push_event(
|
||||
job_id: str, event_type: str, data: dict, prefix: str = "chunk_events"
|
||||
) -> None:
|
||||
"""Push an event to the Redis list for a job."""
|
||||
r = _get_redis()
|
||||
key = f"chunk_events:{job_id}"
|
||||
key = f"{prefix}:{job_id}"
|
||||
event = json.dumps({"event": event_type, **data})
|
||||
r.rpush(key, event)
|
||||
r.expire(key, 3600)
|
||||
|
||||
|
||||
def poll_events(job_id: str, cursor: int = 0) -> tuple[list[dict], int]:
|
||||
def poll_events(
|
||||
job_id: str, cursor: int = 0, prefix: str = "chunk_events"
|
||||
) -> tuple[list[dict], int]:
|
||||
"""Poll new events from Redis. Returns (events, new_cursor)."""
|
||||
r = _get_redis()
|
||||
key = f"chunk_events:{job_id}"
|
||||
key = f"{prefix}:{job_id}"
|
||||
raw_events = r.lrange(key, cursor, -1)
|
||||
parsed = []
|
||||
for raw in raw_events:
|
||||
|
||||
Reference in New Issue
Block a user