Repository navigation
Replies: 2 comments 1 reply
|
Thank you. An admin view of the job queue with retry and cleanup is on the list. I have not scheduled it yet. |
|
Thank you @murtaza-nasir, I would like to pick this up. Before writing code I re-read the request against master (v0.11.10), and a few things moved since it was written. What changed:
Proposed scope: one joined, filtered and paginated GET /admin/jobs with sanitized entries and per-queue counts, a Jobs tab for full administrators, and retry, delete/cancel and clear actions that reuse the existing queue logic. No titles, parameters, provider task handles or full error text in the response. Three questions:
I can send the backend and its tests first and the tab second if you prefer smaller changes, or one PR if you would rather review it as a whole. |
Uh oh!
There was an error while loading. Please reload this page.
Description
Administrators can see only aggregate job numbers in System Statistics, so they cannot tell which jobs are waiting, which are running, for which user, or why a job failed. The only job-level view is the per-user endpoint at
src/api/recordings.py:2695-2766, which filters to the signed-in user and to the last hour (src/api/recordings.py:2713-2723), and the only failure detail is the "latest failed recordings" list atsrc/services/admin_stats.py:191-198, which exposes recording titles.This matters when a queue stalls or a user reports a stuck upload, because the administrator has to correlate counts with logs or impersonate the user to inspect or retry the work. The queue already stores everything needed for triage, including status, job type, user, retry count, progress, timestamps, and error text (
src/models/processing_job.py:12-76).The queue also already computes per-queue counts and fair-turn order (
src/services/job_queue.py:918-996). What is missing is a full-administrator read and management surface that uses that data without exposing user content.Affected Version
v0.10.21-alpha
Requested Feature
Add a "Jobs" tab to the admin dashboard for full administrators. The tab lists every
ProcessingJobacross all users and all queues, with filters for status, queue, and user, bounded pagination, per-queue counts, and row actions for retrying failed jobs, deleting queued or failed jobs, and clearing completed jobs.The view shows operational identifiers and status only. It never includes recording titles, job parameters, provider task handles, or full error text.
Benefits:
Technical requirements:
Proposed Implementation
src/services/admin_jobs.py, that owns the list query, the sanitized serializer, and the per-queue counts. Keep the route insrc/api/admin.pythin so the same shaping is reused by every admin response and tested through the HTTP boundary.db.session.query(ProcessingJob, User.username).join(User, User.id == ProcessingJob.user_id), and add filters before the count and the page slice. JoinUseronce for the page instead of callingdb.session.getper row, and do not joinRecordingat all because the response has no recording title or filename.GET /admin/jobs:statuswithqueued,processing,completed, andfailed;queuewithtranscription,summary,index, andconvert;user_idas an integer; andusernameas a case-insensitive substring. Ignore an unknown value rather than returning an error, acceptrunningas an alias forprocessing, and document that the stored word isprocessingwhile the interface may label it "Running".job_queue.turn_order(job_queue.jobs_for_queue(name))(src/services/job_queue.py:346-388), count theprocessingjobs for that queue's job types, and map each queued job id to its one-based index plus that processing count, exactly assrc/api/recordings.py:2725-2734does. Jobs in other statuses get a null position.ProcessingJob.to_dict()(src/models/processing_job.py:60-76), because that method returns the full error text and a later model change could add a private field to the response by accident. The entry containsid,recording_id,user_id,username,status,job_type,queue_type,position,is_new_upload,retry_count,progress_done,progress_total,created_at,started_at,completed_at,error_kind, and a truncatederror_message; derivequeue_typewithqueue_name_for(job.job_type)(src/services/job_queue.py:120-125) and build the queue filter fromQUEUES(src/services/job_queue.py:42-52).error_kindfromis_permanent_error(job.error_message)(src/services/error_classification.py:17-73), so a failed job reportspermanentortransientand a job without an error message reports null. This keeps the retry advice consistent with the policy that already decides automatic retries.sanitize_error_message(src/utils/error_formatting.py:440-466) or, if the raw text must be preserved, withtruncate_middle(raw, 500)(src/utils/error_formatting.py:349-363). Do not return the fullerror_message,params, orprovider_taskfields (src/models/processing_job.py:27-46).src/api/admin.py:140-182). Returnpage,per_page,total,total_pages,has_next, andhas_prevunderpagination.processingfirst, thenqueued, thenfailed, thencompleted; withinqueuedshow the oldest job first so the queue drains down the page, and within the other statuses show the newest first. Use the job id as the final tie-breaker.queuesfromjob_queue.get_queue_status()(src/services/job_queue.py:918-975), normalized totranscription,summary,index, andconvert, each withqueued,processing, andworkers. Leave out theis_runningflag because it describes the process that serves the request, not the instance, and would mislead an administrator in a multi-process deployment.db.session.expire_all()before the list query, followingsrc/api/recordings.py:2707-2708, so a long-lived session does not show a job as queued after a worker has claimed it.POST /admin/jobs/<int:job_id>/retry,DELETE /admin/jobs/<int:job_id>, andPOST /admin/jobs/clear-completed. Guard each withlogin_required, an explicitcurrent_user.is_admincheck likesrc/api/admin.py:548-550, and the normal CSRF check, which a valid API token already bypasses.src/api/recordings.py:2769-2878into shared helpers, for example insrc/services/admin_jobs.py, and call them from both the existing per-user routes and the new admin routes. The retry helper keeps the active-job check that protectsux_processing_job_active_type(src/init_db.py:1083) and resetsstatus,error_message,retry_count,started_at,completed_at,progress_done, andprogress_total.queuedandfailed, return HTTP 409 forprocessing, and leavecompletedcleanup toclear-completed. Preserve the existing side effect for a failed job withis_new_upload=True, which removes the recording and its audio along with all of its jobs (src/api/recordings.py:2834-2846), and state that consequence in the confirmation dialog.templates/admin.html:178-209) withv-if="!isTeamAdminOnly", and add a matchingtab-contentblock that follows the User Management table and System Statistics card patterns. Load it from the existingwatch(activeTab)hook (templates/admin.html:4188-4215) and reuse theloadUserspagination and request pattern (templates/admin.html:2434-2459).adminDashboard.jobsPageinstatic/locales/en.jsonand in the other six locale files, next to the existing job queue labels (static/locales/en.json:637-638). Add any new API error code, for examplejob_not_deletable, underserver.apiErrorsoapi_error()can translate it.Unit tests
Add
tests/test_admin_job_queue.py, following the shared-database fixtures and login clients used bytests/test_admin_stats.py:36-66and the job creation style intests/test_job_queue_turns.py. The tests below assert observable HTTP behavior and clean up every created row.test_admin_jobs_requires_full_admin: create a full admin, a group admin with aGroupMembershiprole ofadmin, and a regular user; assert the full admin gets 200 and both other accounts get 403 onGET /admin/jobs.test_admin_jobs_sanitizes_entries: create one failed job with a recording title,params,provider_task, and a 2000-charactererror_message; assert the entry has norecording_title,params, orprovider_taskkeys, thaterror_messageis at most 500 characters, and thaterror_kindispermanentortransient.test_admin_jobs_filters_by_status_queue_and_user: create jobs for two users across the transcription, summary, index, and convert queues; assert thatstatus=failed,queue=index,user_id=<id>, andusername=<prefix>each return only the matching subset.test_admin_jobs_pagination_bounds_and_defaults: create 30 jobs; requestpage=2&per_page=10and assert 10 rows,total=30,total_pages=3,has_next=true, andhas_prev=true; then requestper_page=0,per_page=100000, andpage=999and assert the default, the cap, and the clamped last page.test_admin_jobs_positions_match_the_scheduler: create interleaved queued jobs for two users in one queue plus one processing job; assert each reported position equals theturn_orderindex plus the processing count, and that non-queued jobs report null.test_admin_job_retry_only_failed: create a failed job and assert retry returns 200 withstatus=queued,retry_count=0, and cleared timestamps, progress, and error; assert a queued or processing job returns 400 and an unknown id returns 404.test_admin_job_retry_rejects_an_active_job: create a failed job and an active job of the same recording and type; assert the retry returns 409 with the existingrecording_already_processingcode.test_admin_job_delete_respects_status: assert a queued job is removed, a failed job is removed, and a processing or completed job returns 409 withjob_not_deletable.test_admin_job_delete_failed_new_upload_removes_the_recording: create a failed job withis_new_upload=Trueand assert the recording row and its audio path are gone after the delete, matching the per-user behavior.test_admin_clear_completed_removes_only_completed: create one completed, one failed, and one queued job; assert the endpoint deletes only the completed row and returnsdeleted=1.test_admin_jobs_counts_match_the_queue: create one queued and one processing job; assert thequeuesblock reports the same counts asjob_queue.get_queue_status()for the affected queue and still reports the configured worker count.Expected Behavior
GET /admin/jobsreturns HTTP 200 with ajobslist, apaginationobject, and aqueuesobject for a full administrator, and HTTP 403 for a group administrator or a regular user.Root Cause Analysis
The queue stores enough state to answer every triage question, but the only read endpoint is scoped to the current user and to the last hour, excludes the index queue, and includes recording titles (
src/api/recordings.py:2713-2761). The only global view is the aggregate counters atsrc/api/admin.py:568-576and the latest-failures list atsrc/services/admin_stats.py:191-198, and neither exposes job ids, queues, positions, retry counts, or per-job progress.The action endpoints also enforce ownership, because retry and delete compare
job.user_idwithcurrent_user.idand return 403 otherwise (src/api/recordings.py:2780-2784,src/api/recordings.py:2831-2832), and clear-completed always filters by the current user (src/api/recordings.py:2867-2870). As a result, a full administrator who is not the job owner can see the aggregate problem but cannot inspect, retry, or remove the job, which is why the requested surface does not exist today.Additional Context
Verified against the running instance at v0.10.21-alpha. The database held 73
processing_jobrows across four accounts, 58 completed and 15 failed, and the per-user endpoint returned an empty list for the administrator because the five jobs owned by that account were older than the one-hour window and the other 68 belonged to other accounts:The global counters reduced the same 73 rows to three numbers, one of which counted only failures completed in the last seven days. That response carried no job identifier, queue name, user, position, or error kind:
An administrator could not act on another user's failed job through the existing endpoints. Both calls returned the same refusal:
No admin job route exists. Candidate paths returned HTTP 404, while the per-user route answered:
This request does not change the existing list. It gives administrators a less invasive place to work and a reason to stop relying on titles for triage.
This request leaves several items out of scope. It does not add cancellation, polling or push updates, free-form sorting beyond the fixed status order and the fair-turn position column, saved filter preferences, retry policy changes, group-admin access to the global queue, or any change to the per-user job endpoints or their tests.
All reactions