Add cancel job button and improve jobs table UI

- Remove "All Jobs" title
- Move Status column to front of table
- Add Cancel button for in-progress jobs
- Add cancel endpoint: POST /pypi/cache/cancel/{package_name}
- Add btn-danger CSS styling
This commit is contained in:
Mondo Diaz
2026-02-02 15:18:59 -06:00
parent 415ad9a29a
commit 361210a2bc
5 changed files with 114 additions and 21 deletions

View File

@@ -699,3 +699,37 @@ def retry_all_failed_tasks(db: Session) -> int:
logger.info(f"Reset {count} failed tasks for retry")
return count
def cancel_cache_task(db: Session, package_name: str) -> Optional[PyPICacheTask]:
"""
Cancel an in-progress or pending cache task.
Args:
db: Database session.
package_name: The package name to cancel.
Returns:
The cancelled task, or None if not found.
"""
normalized = re.sub(r"[-_.]+", "-", package_name).lower()
task = (
db.query(PyPICacheTask)
.filter(
PyPICacheTask.package_name == normalized,
PyPICacheTask.status.in_(["pending", "in_progress"]),
)
.first()
)
if not task:
return None
task.status = "failed"
task.completed_at = datetime.utcnow()
task.error_message = "Cancelled by admin"
db.commit()
logger.info(f"Cancelled cache task: {normalized}")
return task