Skip to content

refactor(jobs): convert jobs API requests to server functions#1008

Merged
igboyes merged 6 commits into
mainfrom
igboyes/vir-2386-convert-jobs-api-requests-to-server-functions
Jun 1, 2026
Merged

refactor(jobs): convert jobs API requests to server functions#1008
igboyes merged 6 commits into
mainfrom
igboyes/vir-2386-convert-jobs-api-requests-to-server-functions

Conversation

@igboyes
Copy link
Copy Markdown
Member

@igboyes igboyes commented Jun 1, 2026

Summary

  • Replaces superagent-based findJobs and getJob React Query calls with TanStack Start server functions backed by a direct Drizzle/Postgres query, eliminating the round-trip through the Python REST API for job reads.
  • Adds the Drizzle schema mirror for the jobs, job_samples, job_indexes, job_subtractions, and job_analyses tables; reconstructs the legacy args map from the resource junction tables at read time.
  • Fixes the build_index job detail view: the reference id was previously missing because it is not stored in the job args — the detail now fetches the index record and derives ref_id from it, restoring the broken reference and index links. Also suppresses React Query retries for UnauthorizedError/ForbiddenError thrown by server functions (status codes are stripped at the RPC boundary).

Test plan

  • Job list loads and paginates correctly; state filter chips work.
  • Job detail renders for each workflow type (build_index, pathoscope_bowtie, nuvs, create_subtraction, …).
  • build_index job detail shows working reference and index links.
  • Logging out while a job query is in flight redirects to /login without visible retry delay.
  • JobDetail.test.tsx passes (pnpm --filter @virtool/web exec vitest run src/jobs/components/__tests__/JobDetail.test.tsx).
  • JobList.test.tsx passes (pnpm --filter @virtool/web exec vitest run src/jobs/components/__tests__/JobList.test.tsx).

igboyes added 5 commits May 29, 2026 15:45
Move the read-only jobs list and detail queries off the legacy superagent
API client and onto TanStack Start server functions following the
data.ts -> functions.ts layering.

- add a Drizzle mirror of the jobs table and its resource junction tables
- data.ts replicates the Python find() counts/pagination and get() args
  reconstruction, porting compute_progress
- functions.ts validates input with zod and maps JobNotFoundError to 404
- queries.ts keeps its query keys, cache seeding, and zod parsing intact
- mock the jobs server functions at the boundary in tests, as for users
data.ts owns the canonical JOB_STATES tuple and derives JobState from it; functions.ts builds its zod enum with z.enum(JOB_STATES) instead of re-spelling the literals.
build_index jobs carry an index_id but not the reference id, so JobArgs
rendered Reference and Index links pointing at /refs/undefined. Resolve
the reference from the index in JobDetail and inject it into the job args
before rendering, keeping both fetches under one loading gate so the rows
do not pop in. useFetchIndex gains an opt-out so non-index jobs skip the
request. Adds a JobDetail test covering the link derivation.
Server-function errors cross the RPC boundary as plain Errors with only
name/message preserved — the HTTP status from setResponseStatus is not
attached. Match UnauthorizedError / ForbiddenError by name so a
401/403 (e.g. after logout) rejects immediately instead of retrying
~4× while the screen sits blank before the route bounces to /login.
@linear-code
Copy link
Copy Markdown

linear-code Bot commented Jun 1, 2026

VIR-2386

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request migrates the jobs feature to use TanStack Start server functions and Postgres (via Drizzle ORM) instead of direct API client calls to the legacy Python API. It introduces the read-only database schema for jobs, implements the findJobs and getJob server functions, and updates the UI components and routing logic to integrate these changes. Feedback on the changes highlights a critical issue where the rethrowAsHttp helper (wrapped in createServerOnlyFn) is not awaited, which will lead to unhandled promise rejections. Additionally, an optimization is suggested for the findJobs query to conditionally execute the foundCount database query only when a state filter is active.

Comment thread apps/web/src/server/jobs/functions.ts
Comment thread apps/web/src/server/jobs/data.ts Outdated
The getJob handler did not await rethrowAsHttp, which is wrapped in
createServerOnlyFn and returns a promise. Errors thrown inside it became
unhandled rejections and the handler returned undefined instead of the
404 response.

Also skip the redundant found-count query in findJobs when no state
filter is active, reusing the total count instead.
@igboyes igboyes merged commit 021386f into main Jun 1, 2026
9 of 10 checks passed
@igboyes igboyes deleted the igboyes/vir-2386-convert-jobs-api-requests-to-server-functions branch June 1, 2026 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant