30 lines
852 B
Python
30 lines
852 B
Python
"""岗位下架服务
|
|
|
|
每天定时执行,将 create_time 超过 N 天的岗位标记为已失效。
|
|
"""
|
|
|
|
from sqlalchemy import text
|
|
|
|
from app.config import settings
|
|
from app.core.database import MysqlSession
|
|
from app.core.logger import log
|
|
|
|
|
|
async def run_job_expire() -> None:
|
|
"""下架过期岗位"""
|
|
days = int(settings.job_expire_days)
|
|
async with MysqlSession() as mysql:
|
|
result = await mysql.execute(
|
|
text(f"""
|
|
UPDATE bg_job
|
|
SET status = 2, update_time = NOW()
|
|
WHERE status = 0
|
|
AND create_time < DATE_SUB(NOW(), INTERVAL {days} DAY)
|
|
"""),
|
|
)
|
|
await mysql.commit()
|
|
affected = result.rowcount
|
|
|
|
if affected > 0:
|
|
log.info("岗位下架:{}条岗位已标记为失效(超过{}天)", affected, days)
|