ЛР5 - БВТ2302 - Зюлина - на 3
This commit is contained in:
+27
@@ -0,0 +1,27 @@
|
||||
"""Redis Streams producer for durable attachment jobs."""
|
||||
import json
|
||||
import os
|
||||
from datetime import datetime, timezone
|
||||
import redis
|
||||
|
||||
QUEUE = os.getenv("ATTACHMENT_QUEUE", "attachment.jobs.v1")
|
||||
CONSUMER_GROUP = os.getenv("ATTACHMENT_CONSUMER_GROUP", "attachment-workers-v1")
|
||||
MAX_ATTEMPTS = int(os.getenv("JOB_MAX_ATTEMPTS", "5"))
|
||||
|
||||
|
||||
def client():
|
||||
return redis.Redis.from_url(os.environ["BROKER_URL"], decode_responses=True,
|
||||
socket_connect_timeout=3, socket_timeout=10,
|
||||
retry_on_timeout=True)
|
||||
|
||||
|
||||
def publish(attachment_id, job_id, attempt=1):
|
||||
job = {"schema_version": 1, "job_id": job_id,
|
||||
"type": "attachment.process.v1", "attachment_id": attachment_id,
|
||||
"pipeline_version": 1, "attempt": attempt,
|
||||
"created_at": datetime.now(timezone.utc).isoformat().replace("+00:00", "Z")}
|
||||
client().xadd(QUEUE, {"body": json.dumps(job, separators=(",", ":"))})
|
||||
|
||||
|
||||
def ping():
|
||||
client().ping()
|
||||
Reference in New Issue
Block a user