refactor(preview service): send results to REST API#5038
refactor(preview service): send results to REST API#5038iainsproat wants to merge 8 commits intomainfrom
Conversation
- matches pattern used in file import service - removes overhead of creating & managing a queue for responses
- REST AP requires streams:write to add preview
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the preview service to send results synchronously over HTTP instead of via a response queue, simplifying the messaging pattern.
- Renamed the job payload field from
responseQueuetoresponseUrlwith descriptive Zod schemas - Removed response-queue handling code and introduced a new REST endpoint to receive and process preview results
- Updated preview-service to
POSTresults to the new endpoint and removed the response queue
Reviewed Changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| packages/shared/src/workers/previews/job.ts | Renamed responseQueue to responseUrl and added .describe notes |
| packages/server/modules/previews/services/responses.ts | Removed legacy response-queue consumer service |
| packages/server/modules/previews/services/createObjectPreview.ts | Added Streams.Write scope and passed responseUrl |
| packages/server/modules/previews/resultListener.ts | Dropped obsolete buildConsumePreviewResult and DB client logic |
| packages/server/modules/previews/rest/router.ts | Added POST /results endpoint and removed queue-based handlers |
| packages/server/modules/previews/queues/previews.ts | Simplified to request-only queue factory |
| packages/server/modules/previews/observability/metrics.ts | Removed response-queue metrics |
| packages/server/modules/previews/index.ts | Switched to single queue and wired in the new router |
| packages/server/modules/previews/domain/operations.ts | Updated request types to include responseUrl |
| packages/server/modules/previews/clients/bull.ts | Renamed createRequestAndResponseQueues to createRequestQueue |
| packages/preview-service/src/results.ts | Implemented sendResult to POST over HTTP |
| packages/preview-service/src/main.ts | Replaced response-queue logic with HTTP sender |
Comments suppressed due to low confidence (4)
packages/server/modules/previews/rest/router.ts:354
- The function
getProjectDbClientis used here but not imported. Please addimport { getProjectDbClient } from '@/modules/multiregion/utils/dbSelector'at the top of the file.
const projectDb = await getProjectDbClient({ projectId })
packages/server/modules/previews/rest/router.ts:321
- The function
getStreamFactoryis used here but not imported. Please add the appropriate import (e.g.import { getStreamFactory } from '@/modules/core/repositories/streams') at the top of the file.
getStream: getStreamFactory({ db })
packages/server/modules/previews/rest/router.ts:2
- [nitpick] The
corsimport is not used in this file. Consider removing this unused import to clean up the code.
import cors from 'cors'
packages/server/modules/previews/rest/router.ts:3
- [nitpick] The
validateScopesandauthorizeResolverimports are not used in this file. Consider removing these unused imports.
import { validateScopes, authorizeResolver } from '@/modules/shared'
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5038 +/- ##
==========================================
- Coverage 58.76% 58.67% -0.09%
==========================================
Files 118 118
Lines 4637 4644 +7
Branches 531 531
==========================================
Hits 2725 2725
- Misses 1912 1919 +7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…e-response-by-rest-api' into iain/preview-service-response-by-rest-api
Description & motivation
When designing the file import service, we simplified the pattern used by microservices when sending results. Instead of creating an additional queue and managing async message passing, we synchronously send the result to a REST API endpoint.
This refactor applies this same pattern to the preview service.
Changes:
stream:writepermissions in addition tostream:readPOST /api/projects/:streamId/previews/jobs/:jobId/resultsto handle preview service responsesspeckle_server_preview_jobs_response_queue_pendingTo-do before merge:
Screenshots:
Validation of changes:
Checklist:
References