Remove proactive PyPI dependency caching feature
The background task queue for proactively caching package dependencies was causing server instability and unnecessary growth. The PyPI proxy now only caches packages on-demand when users request them. Removed: - PyPI cache worker (background task queue and worker pool) - PyPICacheTask model and related database schema - Cache management API endpoints (/pypi/cache/*) - Background Jobs admin dashboard - Dependency extraction and queueing logic Kept: - On-demand package caching (still works when users request packages) - Async httpx for non-blocking downloads (prevents health check failures) - URL-based cache lookups for deduplication
This commit is contained in:
@@ -12,7 +12,6 @@ import APIKeysPage from './pages/APIKeysPage';
|
||||
import AdminUsersPage from './pages/AdminUsersPage';
|
||||
import AdminOIDCPage from './pages/AdminOIDCPage';
|
||||
import AdminCachePage from './pages/AdminCachePage';
|
||||
import AdminJobsPage from './pages/AdminJobsPage';
|
||||
import ProjectSettingsPage from './pages/ProjectSettingsPage';
|
||||
import TeamsPage from './pages/TeamsPage';
|
||||
import TeamDashboardPage from './pages/TeamDashboardPage';
|
||||
@@ -53,7 +52,6 @@ function AppRoutes() {
|
||||
<Route path="/admin/users" element={<AdminUsersPage />} />
|
||||
<Route path="/admin/oidc" element={<AdminOIDCPage />} />
|
||||
<Route path="/admin/cache" element={<AdminCachePage />} />
|
||||
<Route path="/admin/jobs" element={<AdminJobsPage />} />
|
||||
<Route path="/teams" element={<TeamsPage />} />
|
||||
<Route path="/teams/:slug" element={<TeamDashboardPage />} />
|
||||
<Route path="/teams/:slug/settings" element={<TeamSettingsPage />} />
|
||||
|
||||
@@ -747,58 +747,3 @@ export async function testUpstreamSource(id: string): Promise<UpstreamSourceTest
|
||||
return handleResponse<UpstreamSourceTestResult>(response);
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// PyPI Cache Jobs API
|
||||
// =============================================================================
|
||||
|
||||
import {
|
||||
PyPICacheStatus,
|
||||
PyPICacheTask,
|
||||
PyPICacheActiveTask,
|
||||
PyPICacheRetryResponse,
|
||||
} from './types';
|
||||
|
||||
export async function getPyPICacheStatus(): Promise<PyPICacheStatus> {
|
||||
const response = await fetch('/pypi/cache/status', {
|
||||
credentials: 'include',
|
||||
});
|
||||
return handleResponse<PyPICacheStatus>(response);
|
||||
}
|
||||
|
||||
export async function getPyPICacheFailedTasks(limit: number = 50): Promise<PyPICacheTask[]> {
|
||||
const response = await fetch(`/pypi/cache/failed?limit=${limit}`, {
|
||||
credentials: 'include',
|
||||
});
|
||||
return handleResponse<PyPICacheTask[]>(response);
|
||||
}
|
||||
|
||||
export async function getPyPICacheActiveTasks(limit: number = 50): Promise<PyPICacheActiveTask[]> {
|
||||
const response = await fetch(`/pypi/cache/active?limit=${limit}`, {
|
||||
credentials: 'include',
|
||||
});
|
||||
return handleResponse<PyPICacheActiveTask[]>(response);
|
||||
}
|
||||
|
||||
export async function retryPyPICacheTask(packageName: string): Promise<PyPICacheRetryResponse> {
|
||||
const response = await fetch(`/pypi/cache/retry/${encodeURIComponent(packageName)}`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
});
|
||||
return handleResponse<PyPICacheRetryResponse>(response);
|
||||
}
|
||||
|
||||
export async function retryAllPyPICacheTasks(): Promise<PyPICacheRetryResponse> {
|
||||
const response = await fetch('/pypi/cache/retry-all', {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
});
|
||||
return handleResponse<PyPICacheRetryResponse>(response);
|
||||
}
|
||||
|
||||
export async function cancelPyPICacheTask(packageName: string): Promise<PyPICacheRetryResponse> {
|
||||
const response = await fetch(`/pypi/cache/cancel/${encodeURIComponent(packageName)}`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
});
|
||||
return handleResponse<PyPICacheRetryResponse>(response);
|
||||
}
|
||||
|
||||
@@ -195,17 +195,6 @@ function Layout({ children }: LayoutProps) {
|
||||
</svg>
|
||||
Cache Management
|
||||
</NavLink>
|
||||
<NavLink
|
||||
to="/admin/jobs"
|
||||
className="user-menu-item"
|
||||
onClick={() => setShowUserMenu(false)}
|
||||
>
|
||||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<rect x="2" y="7" width="20" height="14" rx="2" ry="2"/>
|
||||
<path d="M16 21V5a2 2 0 0 0-2-2h-4a2 2 0 0 0-2 2v16"/>
|
||||
</svg>
|
||||
Background Jobs
|
||||
</NavLink>
|
||||
</>
|
||||
)}
|
||||
<div className="user-menu-divider"></div>
|
||||
|
||||
@@ -1,470 +0,0 @@
|
||||
.admin-jobs-page {
|
||||
padding: 2rem;
|
||||
max-width: 1400px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.admin-jobs-page h1 {
|
||||
margin: 0;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.admin-jobs-page h2 {
|
||||
margin: 0;
|
||||
color: var(--text-primary);
|
||||
font-size: 1.25rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.admin-jobs-page h3 {
|
||||
margin: 1.5rem 0 1rem;
|
||||
color: var(--text-primary);
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
/* Page Header */
|
||||
.page-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.header-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.auto-refresh-toggle {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
color: var(--text-secondary);
|
||||
cursor: pointer;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.auto-refresh-toggle input {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
/* Messages */
|
||||
.success-message {
|
||||
padding: 0.75rem 1rem;
|
||||
background-color: rgba(16, 185, 129, 0.1);
|
||||
border: 1px solid rgba(16, 185, 129, 0.3);
|
||||
border-radius: 4px;
|
||||
color: #10b981;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.error-message {
|
||||
padding: 0.75rem 1rem;
|
||||
background-color: rgba(239, 68, 68, 0.1);
|
||||
border: 1px solid rgba(239, 68, 68, 0.3);
|
||||
border-radius: 4px;
|
||||
color: #ef4444;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.loading-text {
|
||||
color: var(--text-secondary);
|
||||
padding: 2rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.success-text {
|
||||
color: #10b981;
|
||||
padding: 1rem;
|
||||
text-align: center;
|
||||
background: rgba(16, 185, 129, 0.1);
|
||||
border-radius: 4px;
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
.empty-message {
|
||||
color: var(--text-secondary);
|
||||
font-style: italic;
|
||||
padding: 2rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/* Overall Progress Bar */
|
||||
.overall-progress {
|
||||
background: var(--bg-secondary);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 8px;
|
||||
padding: 1rem 1.5rem;
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.progress-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
|
||||
.progress-label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
font-weight: 500;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.progress-stats {
|
||||
font-size: 0.9rem;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.progress-bar-container {
|
||||
height: 8px;
|
||||
background: var(--bg-tertiary);
|
||||
border-radius: 4px;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.progress-bar-fill {
|
||||
height: 100%;
|
||||
background: linear-gradient(90deg, #10b981, #34d399);
|
||||
border-radius: 4px;
|
||||
transition: width 0.3s ease;
|
||||
}
|
||||
|
||||
.progress-bar-active {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
width: 30%;
|
||||
height: 100%;
|
||||
background: linear-gradient(90deg, transparent, rgba(59, 130, 246, 0.5), transparent);
|
||||
animation: progress-sweep 1.5s ease-in-out infinite;
|
||||
}
|
||||
|
||||
@keyframes progress-sweep {
|
||||
0% {
|
||||
transform: translateX(-100%);
|
||||
}
|
||||
100% {
|
||||
transform: translateX(400%);
|
||||
}
|
||||
}
|
||||
|
||||
/* Jobs Section */
|
||||
.jobs-section {
|
||||
background: var(--bg-secondary);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 8px;
|
||||
padding: 1.5rem;
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.section-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
/* Jobs Table */
|
||||
.jobs-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
background: var(--bg-primary);
|
||||
border-radius: 4px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.jobs-table th,
|
||||
.jobs-table td {
|
||||
padding: 0.75rem 1rem;
|
||||
text-align: center;
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
.jobs-table th {
|
||||
background: var(--bg-tertiary);
|
||||
font-weight: 600;
|
||||
color: var(--text-secondary);
|
||||
font-size: 0.85rem;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.jobs-table tr:last-child td {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.jobs-table .package-name {
|
||||
font-family: monospace;
|
||||
font-weight: 500;
|
||||
color: var(--text-primary);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
/* Job Row States */
|
||||
.job-row.in_progress {
|
||||
background-color: rgba(59, 130, 246, 0.05);
|
||||
}
|
||||
|
||||
.job-row.failed {
|
||||
background-color: rgba(239, 68, 68, 0.05);
|
||||
}
|
||||
|
||||
.job-row.stale {
|
||||
background-color: rgba(245, 158, 11, 0.1);
|
||||
}
|
||||
|
||||
.job-row:hover {
|
||||
background-color: var(--bg-tertiary);
|
||||
}
|
||||
|
||||
/* Type Badge */
|
||||
.type-badge {
|
||||
display: inline-block;
|
||||
padding: 0.2rem 0.5rem;
|
||||
border-radius: 4px;
|
||||
font-size: 0.7rem;
|
||||
font-weight: 600;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.type-badge.pypi {
|
||||
background-color: rgba(59, 130, 246, 0.15);
|
||||
color: var(--color-primary, #3b82f6);
|
||||
}
|
||||
|
||||
/* Status Cell */
|
||||
.status-cell {
|
||||
min-width: 120px;
|
||||
}
|
||||
|
||||
.status-with-progress {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.25rem;
|
||||
}
|
||||
|
||||
.mini-progress-bar {
|
||||
width: 80px;
|
||||
height: 4px;
|
||||
background: var(--bg-tertiary);
|
||||
border-radius: 2px;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.mini-progress-fill {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 40%;
|
||||
height: 100%;
|
||||
background: var(--color-primary, #3b82f6);
|
||||
border-radius: 2px;
|
||||
animation: mini-progress 1s ease-in-out infinite;
|
||||
}
|
||||
|
||||
@keyframes mini-progress {
|
||||
0%, 100% {
|
||||
left: 0;
|
||||
width: 40%;
|
||||
}
|
||||
50% {
|
||||
left: 60%;
|
||||
width: 40%;
|
||||
}
|
||||
}
|
||||
|
||||
/* Status Badges */
|
||||
.status-badge {
|
||||
display: inline-block;
|
||||
padding: 0.2rem 0.5rem;
|
||||
border-radius: 4px;
|
||||
font-size: 0.75rem;
|
||||
font-weight: 500;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.status-badge.running,
|
||||
.status-badge.working {
|
||||
background-color: rgba(59, 130, 246, 0.15);
|
||||
color: var(--color-primary, #3b82f6);
|
||||
}
|
||||
|
||||
.status-badge.failed {
|
||||
background-color: rgba(239, 68, 68, 0.15);
|
||||
color: #ef4444;
|
||||
}
|
||||
|
||||
.status-badge.pending {
|
||||
background-color: rgba(245, 158, 11, 0.15);
|
||||
color: #f59e0b;
|
||||
}
|
||||
|
||||
.status-badge.stale {
|
||||
background-color: rgba(245, 158, 11, 0.15);
|
||||
color: #f59e0b;
|
||||
}
|
||||
|
||||
/* Spinner */
|
||||
.spinner {
|
||||
display: inline-block;
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
border: 2px solid var(--border-color);
|
||||
border-top-color: var(--color-primary, #3b82f6);
|
||||
border-radius: 50%;
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
/* Pulse Indicator */
|
||||
.pulse-indicator {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
background-color: var(--color-primary, #3b82f6);
|
||||
border-radius: 50%;
|
||||
animation: pulse 1.5s ease-in-out infinite;
|
||||
}
|
||||
|
||||
@keyframes pulse {
|
||||
0%, 100% {
|
||||
opacity: 1;
|
||||
transform: scale(1);
|
||||
}
|
||||
50% {
|
||||
opacity: 0.5;
|
||||
transform: scale(1.2);
|
||||
}
|
||||
}
|
||||
|
||||
/* Details Cell */
|
||||
.details-cell {
|
||||
max-width: 200px;
|
||||
}
|
||||
|
||||
.error-text {
|
||||
color: #ef4444;
|
||||
font-size: 0.85rem;
|
||||
display: block;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.version-text {
|
||||
font-family: monospace;
|
||||
font-size: 0.85rem;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.elapsed-time {
|
||||
font-size: 0.75rem;
|
||||
color: var(--text-secondary);
|
||||
font-family: monospace;
|
||||
}
|
||||
|
||||
.timestamp {
|
||||
font-size: 0.85rem;
|
||||
color: var(--text-secondary);
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.actions-cell {
|
||||
white-space: nowrap;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
/* Buttons */
|
||||
.btn {
|
||||
padding: 0.5rem 1rem;
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 4px;
|
||||
background: var(--bg-primary);
|
||||
color: var(--text-primary);
|
||||
cursor: pointer;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.btn:hover {
|
||||
background: var(--bg-tertiary);
|
||||
}
|
||||
|
||||
.btn:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background-color: var(--color-primary);
|
||||
border-color: var(--color-primary);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-primary:hover {
|
||||
background-color: var(--color-primary-hover);
|
||||
}
|
||||
|
||||
.btn-secondary {
|
||||
background-color: var(--bg-tertiary);
|
||||
border-color: var(--border-color);
|
||||
color: var(--text-primary);
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.btn-secondary:hover {
|
||||
background-color: var(--bg-secondary);
|
||||
border-color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.btn-danger {
|
||||
background-color: #ef4444;
|
||||
border-color: #ef4444;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-danger:hover {
|
||||
background-color: #dc2626;
|
||||
border-color: #dc2626;
|
||||
}
|
||||
|
||||
.btn-sm {
|
||||
padding: 0.25rem 0.75rem;
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
|
||||
/* Responsive */
|
||||
@media (max-width: 768px) {
|
||||
.page-header {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.jobs-table {
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
|
||||
.details-cell {
|
||||
max-width: 100px;
|
||||
}
|
||||
|
||||
.progress-header {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
}
|
||||
@@ -1,336 +0,0 @@
|
||||
import { useState, useEffect, useCallback } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useAuth } from '../contexts/AuthContext';
|
||||
import {
|
||||
getPyPICacheStatus,
|
||||
getPyPICacheFailedTasks,
|
||||
getPyPICacheActiveTasks,
|
||||
retryPyPICacheTask,
|
||||
retryAllPyPICacheTasks,
|
||||
cancelPyPICacheTask,
|
||||
} from '../api';
|
||||
import { PyPICacheStatus, PyPICacheTask, PyPICacheActiveTask } from '../types';
|
||||
import './AdminJobsPage.css';
|
||||
|
||||
function AdminJobsPage() {
|
||||
const { user, loading: authLoading } = useAuth();
|
||||
const navigate = useNavigate();
|
||||
|
||||
// PyPI cache status
|
||||
const [cacheStatus, setCacheStatus] = useState<PyPICacheStatus | null>(null);
|
||||
const [failedTasks, setFailedTasks] = useState<PyPICacheTask[]>([]);
|
||||
const [activeTasks, setActiveTasks] = useState<PyPICacheActiveTask[]>([]);
|
||||
const [loadingStatus, setLoadingStatus] = useState(true);
|
||||
const [statusError, setStatusError] = useState<string | null>(null);
|
||||
|
||||
// Action states
|
||||
const [retryingPackage, setRetryingPackage] = useState<string | null>(null);
|
||||
const [retryingAll, setRetryingAll] = useState(false);
|
||||
const [cancelingPackage, setCancelingPackage] = useState<string | null>(null);
|
||||
const [successMessage, setSuccessMessage] = useState<string | null>(null);
|
||||
|
||||
// Auto-refresh
|
||||
const [autoRefresh, setAutoRefresh] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
if (!authLoading && !user) {
|
||||
navigate('/login', { state: { from: '/admin/jobs' } });
|
||||
}
|
||||
}, [user, authLoading, navigate]);
|
||||
|
||||
const loadData = useCallback(async () => {
|
||||
if (!user?.is_admin) return;
|
||||
|
||||
setStatusError(null);
|
||||
try {
|
||||
const [status, failed, active] = await Promise.all([
|
||||
getPyPICacheStatus(),
|
||||
getPyPICacheFailedTasks(100),
|
||||
getPyPICacheActiveTasks(50),
|
||||
]);
|
||||
setCacheStatus(status);
|
||||
setFailedTasks(failed);
|
||||
setActiveTasks(active);
|
||||
} catch (err) {
|
||||
setStatusError(err instanceof Error ? err.message : 'Failed to load status');
|
||||
} finally {
|
||||
setLoadingStatus(false);
|
||||
}
|
||||
}, [user]);
|
||||
|
||||
useEffect(() => {
|
||||
if (user?.is_admin) {
|
||||
loadData();
|
||||
}
|
||||
}, [user, loadData]);
|
||||
|
||||
// Auto-refresh every 5 seconds when enabled
|
||||
useEffect(() => {
|
||||
if (!autoRefresh || !user?.is_admin) return;
|
||||
|
||||
const interval = setInterval(() => {
|
||||
loadData();
|
||||
}, 5000);
|
||||
|
||||
return () => clearInterval(interval);
|
||||
}, [autoRefresh, user, loadData]);
|
||||
|
||||
useEffect(() => {
|
||||
if (successMessage) {
|
||||
const timer = setTimeout(() => setSuccessMessage(null), 3000);
|
||||
return () => clearTimeout(timer);
|
||||
}
|
||||
}, [successMessage]);
|
||||
|
||||
async function handleRetryPackage(packageName: string) {
|
||||
setRetryingPackage(packageName);
|
||||
try {
|
||||
const result = await retryPyPICacheTask(packageName);
|
||||
setSuccessMessage(result.message);
|
||||
await loadData();
|
||||
} catch (err) {
|
||||
setStatusError(err instanceof Error ? err.message : 'Failed to retry');
|
||||
} finally {
|
||||
setRetryingPackage(null);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleRetryAll() {
|
||||
if (!window.confirm('Retry all failed tasks? This will re-queue all failed packages.')) {
|
||||
return;
|
||||
}
|
||||
|
||||
setRetryingAll(true);
|
||||
try {
|
||||
const result = await retryAllPyPICacheTasks();
|
||||
setSuccessMessage(result.message);
|
||||
await loadData();
|
||||
} catch (err) {
|
||||
setStatusError(err instanceof Error ? err.message : 'Failed to retry all');
|
||||
} finally {
|
||||
setRetryingAll(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleCancelPackage(packageName: string) {
|
||||
setCancelingPackage(packageName);
|
||||
try {
|
||||
const result = await cancelPyPICacheTask(packageName);
|
||||
setSuccessMessage(result.message);
|
||||
await loadData();
|
||||
} catch (err) {
|
||||
setStatusError(err instanceof Error ? err.message : 'Failed to cancel');
|
||||
} finally {
|
||||
setCancelingPackage(null);
|
||||
}
|
||||
}
|
||||
|
||||
if (authLoading) {
|
||||
return <div className="admin-jobs-page">Loading...</div>;
|
||||
}
|
||||
|
||||
if (!user?.is_admin) {
|
||||
return (
|
||||
<div className="admin-jobs-page">
|
||||
<div className="error-message">Access denied. Admin privileges required.</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const totalJobs = cacheStatus
|
||||
? cacheStatus.pending + cacheStatus.in_progress + cacheStatus.completed + cacheStatus.failed
|
||||
: 0;
|
||||
|
||||
const completedPercent = totalJobs > 0
|
||||
? Math.round((cacheStatus?.completed ?? 0) / totalJobs * 100)
|
||||
: 0;
|
||||
|
||||
// Combine all jobs into unified list with type column
|
||||
type UnifiedJob = {
|
||||
id: string;
|
||||
type: 'pypi';
|
||||
package: string;
|
||||
status: 'pending' | 'in_progress' | 'completed' | 'failed';
|
||||
depth: number;
|
||||
attempts: number;
|
||||
error?: string | null;
|
||||
started_at?: string | null;
|
||||
failed_at?: string | null;
|
||||
version_constraint?: string | null;
|
||||
};
|
||||
|
||||
const allJobs: UnifiedJob[] = [
|
||||
// Active tasks first
|
||||
...activeTasks.map((t): UnifiedJob => ({
|
||||
id: t.id,
|
||||
type: 'pypi',
|
||||
package: t.package,
|
||||
status: 'in_progress',
|
||||
depth: t.depth,
|
||||
attempts: t.attempts,
|
||||
started_at: t.started_at,
|
||||
version_constraint: t.version_constraint,
|
||||
})),
|
||||
// Then failed tasks
|
||||
...failedTasks.map((t): UnifiedJob => ({
|
||||
id: t.id,
|
||||
type: 'pypi',
|
||||
package: t.package,
|
||||
status: 'failed',
|
||||
depth: t.depth,
|
||||
attempts: t.attempts,
|
||||
error: t.error,
|
||||
failed_at: t.failed_at,
|
||||
})),
|
||||
];
|
||||
|
||||
return (
|
||||
<div className="admin-jobs-page">
|
||||
<div className="page-header">
|
||||
<h1>Background Jobs</h1>
|
||||
<div className="header-actions">
|
||||
<label className="auto-refresh-toggle">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={autoRefresh}
|
||||
onChange={(e) => setAutoRefresh(e.target.checked)}
|
||||
/>
|
||||
Auto-refresh
|
||||
</label>
|
||||
<button className="btn btn-secondary" onClick={loadData} disabled={loadingStatus}>
|
||||
Refresh
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{successMessage && <div className="success-message">{successMessage}</div>}
|
||||
{statusError && <div className="error-message">{statusError}</div>}
|
||||
|
||||
{/* Overall Progress Bar */}
|
||||
{totalJobs > 0 && (
|
||||
<div className="overall-progress">
|
||||
<div className="progress-header">
|
||||
<span className="progress-label">
|
||||
<span className="pulse-indicator"></span>
|
||||
Overall Progress
|
||||
</span>
|
||||
<span className="progress-stats">
|
||||
{cacheStatus?.completed ?? 0} / {totalJobs} completed
|
||||
{(cacheStatus?.in_progress ?? 0) > 0 && ` · ${cacheStatus?.in_progress} active`}
|
||||
{(cacheStatus?.failed ?? 0) > 0 && ` · ${cacheStatus?.failed} failed`}
|
||||
</span>
|
||||
</div>
|
||||
<div className="progress-bar-container">
|
||||
<div
|
||||
className="progress-bar-fill"
|
||||
style={{ width: `${completedPercent}%` }}
|
||||
/>
|
||||
{(cacheStatus?.in_progress ?? 0) > 0 && (
|
||||
<div className="progress-bar-active" />
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Jobs Section */}
|
||||
<section className="jobs-section">
|
||||
{failedTasks.length > 0 && (
|
||||
<div className="section-header">
|
||||
<button
|
||||
className="btn btn-primary"
|
||||
onClick={handleRetryAll}
|
||||
disabled={retryingAll}
|
||||
>
|
||||
{retryingAll ? 'Retrying...' : `Retry All Failed (${failedTasks.length})`}
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{loadingStatus && !cacheStatus ? (
|
||||
<p className="loading-text">Loading job status...</p>
|
||||
) : totalJobs === 0 ? (
|
||||
<p className="empty-message">No jobs yet. Jobs are created when packages are downloaded through the PyPI proxy.</p>
|
||||
) : allJobs.length === 0 ? (
|
||||
<p className="success-text">All {cacheStatus?.completed ?? 0} jobs completed successfully!</p>
|
||||
) : (
|
||||
<table className="jobs-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Status</th>
|
||||
<th>Type</th>
|
||||
<th>Package</th>
|
||||
<th>Depth</th>
|
||||
<th>Attempts</th>
|
||||
<th>Details</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{allJobs.map((job) => {
|
||||
return (
|
||||
<tr key={job.id} className={`job-row ${job.status}`}>
|
||||
<td className="status-cell">
|
||||
{job.status === 'in_progress' ? (
|
||||
<span className="status-badge working">Working</span>
|
||||
) : job.status === 'failed' ? (
|
||||
<span className="status-badge failed">Failed</span>
|
||||
) : (
|
||||
<span className="status-badge pending">Pending</span>
|
||||
)}
|
||||
</td>
|
||||
<td>
|
||||
<span className="type-badge pypi">PyPI</span>
|
||||
</td>
|
||||
<td className="package-name">
|
||||
{job.status === 'in_progress' && <span className="spinner"></span>}
|
||||
{job.package}
|
||||
</td>
|
||||
<td>{job.depth}</td>
|
||||
<td>{job.attempts}</td>
|
||||
<td className="details-cell">
|
||||
{job.status === 'failed' && job.error && (
|
||||
<span className="error-text" title={job.error}>
|
||||
{job.error.length > 40 ? job.error.substring(0, 40) + '...' : job.error}
|
||||
</span>
|
||||
)}
|
||||
{job.status === 'in_progress' && job.version_constraint && (
|
||||
<span className="version-text">{job.version_constraint}</span>
|
||||
)}
|
||||
{job.status === 'failed' && job.failed_at && (
|
||||
<span className="timestamp">
|
||||
{new Date(job.failed_at).toLocaleTimeString()}
|
||||
</span>
|
||||
)}
|
||||
</td>
|
||||
<td className="actions-cell">
|
||||
{job.status === 'failed' && (
|
||||
<button
|
||||
className="btn btn-sm btn-secondary"
|
||||
onClick={() => handleRetryPackage(job.package)}
|
||||
disabled={retryingPackage === job.package}
|
||||
>
|
||||
{retryingPackage === job.package ? '...' : 'Retry'}
|
||||
</button>
|
||||
)}
|
||||
{job.status === 'in_progress' && (
|
||||
<button
|
||||
className="btn btn-sm btn-danger"
|
||||
onClick={() => handleCancelPackage(job.package)}
|
||||
disabled={cancelingPackage === job.package}
|
||||
>
|
||||
{cancelingPackage === job.package ? '...' : 'Cancel'}
|
||||
</button>
|
||||
)}
|
||||
</td>
|
||||
</tr>
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
)}
|
||||
</section>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default AdminJobsPage;
|
||||
@@ -557,35 +557,3 @@ export interface UpstreamSourceTestResult {
|
||||
source_id: string;
|
||||
source_name: string;
|
||||
}
|
||||
|
||||
// PyPI Cache Job types
|
||||
export interface PyPICacheStatus {
|
||||
pending: number;
|
||||
in_progress: number;
|
||||
completed: number;
|
||||
failed: number;
|
||||
}
|
||||
|
||||
export interface PyPICacheTask {
|
||||
id: string;
|
||||
package: string;
|
||||
error: string | null;
|
||||
attempts: number;
|
||||
depth: number;
|
||||
failed_at: string | null;
|
||||
}
|
||||
|
||||
export interface PyPICacheActiveTask {
|
||||
id: string;
|
||||
package: string;
|
||||
version_constraint: string | null;
|
||||
depth: number;
|
||||
attempts: number;
|
||||
started_at: string | null;
|
||||
}
|
||||
|
||||
export interface PyPICacheRetryResponse {
|
||||
message: string;
|
||||
task_id?: string;
|
||||
count?: number;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user