اضافه شدن قابلیت share و نگهداری بلندمدت
Verify / test (push) Failing after 22s

This commit is contained in:
2026-11-09 14:55:36 +03:30
والد a4e8f0c6c0
کامیت 19824bd180
27فایلهای تغییر یافته به همراه267 افزوده شده و 51 حذف شده
+5 -2
مشاهده پرونده
@@ -6,7 +6,7 @@ to Redis. Versioned artifact keys fence out expired worker leases.
"""
import time
from functools import lru_cache
from sqlalchemy import create_engine, String, Text, Float, Integer, select, update, func, text
from sqlalchemy import create_engine, String, Text, Float, Integer, select, update, func, text, or_
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, sessionmaker
from .config import settings
@@ -39,6 +39,9 @@ def engine():
@lru_cache
def sessions(): return sessionmaker(engine(), expire_on_commit=False)
def active_jobs(now):
return or_(Job.expires_at == -1, Job.expires_at > now)
def initialize():
# Initial schema only. Subsequent schema changes must use explicit migrations.
if engine().dialect.name == 'postgresql':
@@ -55,7 +58,7 @@ def claim():
now = time.time()
with sessions().begin() as db:
# Expired jobs are never revived. A crashed worker can be retried once.
eligible = ((Job.status == 'queued') | ((Job.status == 'processing') & (Job.lease_until < now))) & (Job.expires_at > now)
eligible = ((Job.status == 'queued') | ((Job.status == 'processing') & (Job.lease_until < now))) & active_jobs(now)
q = select(Job).where(eligible).order_by(Job.created_at).limit(1)
if engine().dialect.name == 'postgresql': q = q.with_for_update(skip_locked=True)
job = db.scalar(q)