Files
Nexus/server/infrastructure/database/push_schedule_repo.py
T
Your Name 249a1aaed9 重试队列增强 + 审计分页
- 后端: 添加 POST /api/retries/{id}/retry (手动重试) + DELETE /api/retries/{id}
  + 审计日志分页(offset/limit/count) + PushRetryJobRepo新增get_all/get_by_id/delete
- 前端retries: 手动重试按钮、删除按钮、状态过滤、操作人显示、toast反馈
- 前端audit: 分页控件(上一页/下一页)、每页50条、新增retry_job/delete_retry过滤
- 修复index.html: 适配审计API新返回格式(data.items)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-22 09:41:33 +08:00

96 lines
3.3 KiB
Python

"""Nexus — PushSchedule & PushRetryJob Repository (Async SQLAlchemy)"""
from typing import Optional, List
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession
from server.domain.models import PushSchedule, PushRetryJob
class PushScheduleRepositoryImpl:
def __init__(self, session: AsyncSession):
self.session = session
async def get_by_id(self, id: int) -> Optional[PushSchedule]:
result = await self.session.execute(select(PushSchedule).where(PushSchedule.id == id))
return result.scalar_one_or_none()
async def get_all(self) -> List[PushSchedule]:
result = await self.session.execute(select(PushSchedule).order_by(PushSchedule.id))
return list(result.scalars().all())
async def get_enabled(self) -> List[PushSchedule]:
result = await self.session.execute(
select(PushSchedule).where(PushSchedule.enabled == True).order_by(PushSchedule.id)
)
return list(result.scalars().all())
async def create(self, schedule: PushSchedule) -> PushSchedule:
self.session.add(schedule)
await self.session.commit()
await self.session.refresh(schedule)
return schedule
async def update(self, schedule: PushSchedule) -> PushSchedule:
await self.session.commit()
await self.session.refresh(schedule)
return schedule
async def delete(self, id: int) -> bool:
schedule = await self.get_by_id(id)
if schedule:
await self.session.delete(schedule)
await self.session.commit()
return True
return False
class PushRetryJobRepositoryImpl:
def __init__(self, session: AsyncSession):
self.session = session
async def get_pending(self, limit: int = 100) -> List[PushRetryJob]:
result = await self.session.execute(
select(PushRetryJob)
.where(PushRetryJob.status == "pending")
.order_by(PushRetryJob.created_at)
.limit(limit)
)
return list(result.scalars().all())
async def get_all(self, limit: int = 100) -> List[PushRetryJob]:
result = await self.session.execute(
select(PushRetryJob)
.order_by(PushRetryJob.created_at.desc())
.limit(limit)
)
return list(result.scalars().all())
async def get_by_id(self, id: int) -> Optional[PushRetryJob]:
result = await self.session.execute(select(PushRetryJob).where(PushRetryJob.id == id))
return result.scalar_one_or_none()
async def delete(self, id: int) -> bool:
job = await self.get_by_id(id)
if job:
await self.session.delete(job)
await self.session.commit()
return True
return False
async def create(self, job: PushRetryJob) -> PushRetryJob:
self.session.add(job)
await self.session.commit()
await self.session.refresh(job)
return job
async def update_status(self, id: int, status: str, **kwargs) -> PushRetryJob:
job = await self.session.get(PushRetryJob, id)
if job:
job.status = status
for key, value in kwargs.items():
if hasattr(job, key):
setattr(job, key, value)
await self.session.commit()
await self.session.refresh(job)
return job