feat(self-hosted): background tasks, scheduler & file manager for the server flavour#5408
Merged
Merged
Conversation
… to the server flavour Wire the AWS-only background-tasks, scheduler, and file-manager capabilities into the self-hosted Node server flavour, plus the transport fixes needed to run them in a single long-running process. Background tasks: - Register BackgroundTasksServerFeature in the server handler root (in-process worker_thread runner + /background-task route). Root, not per-request, so the shared InternalToken gate is a stable singleton. - WorkerService reads the runtime PORT env instead of the (unset) SERVER_PORT build param. Scheduler: - Wire registerSchedulerServerExtension via the registerSchedulerTransport hook. - Register its RequestContextInitializer via register() (not registerInstance) so it runs after SchedulerModelContextualSchema registers ScheduledActionModel. File manager: - Add a registerFileManagerTransport hook to the shared request stack (replaces the hardcoded FileManagerS3Feature); AWS passes S3, server passes FileManagerServerFeature. - FileManagerServerFeature: register local asset delivery, the upload GraphQL schema (mirrors S3 query names so the SDK is unchanged), and the domain Read/WriteFileMetadata features; resolve config lazily (build params are not registered at register() time). - Add Infra.FileStorage (bakes WEBINY_LOCAL_STORAGE_PATH + WEBINY_UPLOAD_SECRET build params). - resolveServerUrl derives the URL from WEBINY_API_URL/PORT (the DI-native gql context exposes no request headers to resolvers). - SettingsInstaller falls back to WEBINY_API_URL for srcPrefix when there is no CloudFront manifest (AWS-safe). Transport (event-handler-server): - Read binary request bodies as raw Buffers (multipart uploads were utf8-corrupted). - Write Buffer response bodies raw (image delivery was JSON-serialized -> ORB-blocked). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…nsports`
Collapse the three structurally-identical hooks (registerRealtimeTransport /
registerSchedulerTransport / registerFileManagerTransport) into a single
`transports: { realtime?, scheduler?, fileManager? }` object on
RegisterApiRequestStackConfig, plus a shared `TransportRegistrar` type. Behaviour
unchanged — the adapters still run at the same interleave points. Makes "these are all
transport adapters" one named concept and adding a future request-seam transport a single
key rather than a new top-level param. Updates the AWS and server handlers to match.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The `assetDelivery` config knob was never set (both S3 and server callers pass no config), so it was speculative parity. Remove the interface + param; register with `createLocalAssetDeliveryFeature()` defaults. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…rver-bg-scheduler-fm # Conflicts: # packages/project-server/src/infra.ts
Member
Author
|
/vitest |
|
Vitest tests have been initiated (for more information, click here). ✨
❌ Failed packagesDDB+OS
PGlite
|
Member
Author
|
/vitest |
|
Vitest tests have been initiated (for more information, click here). ✨
❌ Failed packagesPGlite
|
…ithub.com/webiny/webiny-js into adrian/self-hosted-server-bg-scheduler-fm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ports the AWS-only background tasks, scheduler, and file manager capabilities to the self-hosted Node server flavour, following the transport-hook pattern established by the WebSockets work (#5393). Builds on the already-shipped server packages (
background-tasks-server,api-scheduler-server,api-file-manager-server) — this PR wires them into the event handler and fixes the gaps that surfaced running them in a single long-running process.Background tasks
BackgroundTasksServerFeaturein the server handler root (in-processworker_threadrunner +/background-taskroute). Root, not per-request — the sharedInternalTokenthat gates the route must be a stable singleton, else the worker's callback 403s.WorkerServicereads the runtimePORTenv (whatrunApiServerinjects and the server listens on) instead of the unsetSERVER_PORTbuild param.Scheduler
registerSchedulerServerExtensionvia theregisterSchedulerTransporthook (Bree/in-process, vs EventBridge).RequestContextInitializerviaregister()rather thanregisterInstance()—@webiny/dirunsregisterInstanceinitializers first, so it was running beforeSchedulerModelContextualSchemaregisteredScheduledActionModel("No registration found for ScheduledActionModel").File manager
registerFileManagerTransporthook to the shared request stack, replacing the hardcodedFileManagerS3Feature— AWS passes S3, server passesFileManagerServerFeature. (Third transport hook alongside realtime + scheduler.)FileManagerServerFeaturenow also registers: local asset delivery (createLocalAssetDeliveryFeature), the upload GraphQL schema (mirrors S3 query names so the SDK is unchanged), and the domainRead/WriteFileMetadatafeatures.FileManagerServerConfigresolves lazily — build params aren't registered at register() time (they land with project extensions later in the request stack).Infra.FileStorageextension bakesWEBINY_LOCAL_STORAGE_PATH+WEBINY_UPLOAD_SECRETbuild params (mirrorsInfra.Sqlite/Infra.Crypto.Encryption).resolveServerUrlderives the URL fromWEBINY_API_URL/PORT— the DI-native gql context exposes no request headers to resolvers.SettingsInstallerfalls back toWEBINY_API_URLforsrcPrefixwhen there's no CloudFront manifest (AWS-safe: AWS still uses the manifest domain).Transport (
event-handler-server)Buffers — the previousraw += chunkutf8-corrupted multipart uploads.Bufferresponse bodies raw — image delivery wasJSON.stringify'd, so browsersERR_BLOCKED_BY_ORB'd it.Verified
Manually: background-task dispatch, scheduler bind, and the full file-manager loop (upload → disk → metadata → transform → deliver, image renders in admin). All changed packages typecheck;
adio+oxlintclean.Follow-ups (not in this PR)
registerRealtimeTransport,registerSchedulerTransport,registerFileManagerTransport) are structurally identical — candidate to collapse into a singletransports: {}config.onServer).🤖 Generated with Claude Code