Files
offerpie_job_cleaner/app/services/zombie_recover_service.py
T
2026-06-02 17:44:03 +08:00

43 lines
1.3 KiB
Python

"""僵尸恢复服务"""
from sqlalchemy import text
from app.core.database import PgSession, MysqlSession
from app.core.logger import log
async def recover_job_zombie() -> None:
"""岗位清洗僵尸恢复:超时10分钟的 cleaning → pending"""
async with PgSession() as pg:
result = await pg.execute(
text("""
UPDATE app_job_data
SET clean_status = 'pending', clean_started_at = NULL
WHERE clean_status = 'cleaning'
AND clean_started_at < NOW() - INTERVAL '10 minutes'
""")
)
await pg.commit()
affected = result.rowcount
if affected > 0:
log.info("岗位僵尸恢复:重置{}条数据", affected)
async def recover_company_zombie() -> None:
"""公司补充僵尸恢复:超时10分钟的 status=3 → 0"""
async with MysqlSession() as mysql:
result = await mysql.execute(
text("""
UPDATE bg_company
SET status = 0, update_time = NOW()
WHERE status = 3
AND update_time < NOW() - INTERVAL 10 MINUTE
""")
)
await mysql.commit()
affected = result.rowcount
if affected > 0:
log.info("公司僵尸恢复:重置{}条数据", affected)