Support existing Cloudflare workers for queue and cron#6935
Open
c-w-xiaohei wants to merge 1 commit into
Open
Conversation
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.
Summary
Allow Cloudflare Queue consumers and Cron triggers to attach to an existing
sst.cloudflare.Worker.Existing behavior is unchanged:
queue.subscribe("consumer.ts")still creates a consumer Worker.queue.subscribe({ handler: "consumer.ts" })still creates a consumer Worker.new sst.cloudflare.Cron(..., { worker: "cron.ts" })still creates a Worker.jobremains supported as before.Why
Cloudflare Workers can handle
fetch,queue, andscheduledevents from the same script. Cloudflare Queue producer bindings and consumer attachments are separate: producers bind a queue to send messages, while a consumer points at a WorkerscriptName. Cron triggers also point at a Worker script.SST already supports the default separated-worker flow by accepting a handler or
WorkerArgsand creating a Worker forQueue.subscribe()andCron. That remains the default.However, SST previously had no way to attach a Queue consumer or Cron trigger to a Worker created earlier in the same app. Users wanting one Worker to serve HTTP traffic, publish messages, process queue batches, and handle schedules had to create raw
cloudflare.QueueConsumerandcloudflare.WorkersCronTriggerresources themselves.Design
This is intentionally scoped to direct
sst.cloudflare.Workerinstances.QueueWorkerSubscriberuses the existing Worker'snodes.workerfor the consumerscriptName.Cronuses the existing Worker'snodes.workerfor the triggerscriptName.WorkerArgsstill use the existingworkerBuilderpath.workerBuilderremains responsible only for creating Workers from source definitions.transform.workeris rejected for an existing Queue subscriber Worker because no new Worker exists to transform.This PR does not add raw
scriptNamesupport,Worker.get(), publicQueueConsumer/CronTriggercomponents, or new deprecations.Testing
Passed:
bun run --cwd platform test test/components/cloudflare-existing-worker.test.tsbun run typecheck:platformbun run build:platformbun run --cwd platform teststill has unrelated existing/environment failures resolving@types/nodein the ALB/Bucket/Service tests, plusERR_TRACE_EVENTS_UNAVAILABLEunhandled errors from Router WAF tests. The new Cloudflare existing Worker test passes in that full run.