Skip to content

Conversation

@dunglas
Copy link
Member

@dunglas dunglas commented Oct 30, 2025

Yet another refactoring and simplification of the extension worker API.

I also pluralized names for consistency with the existing WithWorkers function. I'm not entirely sure about that.

This allows us to greatly simplify extension writing and should increase performance a bit.

Here is the patch for frankenphp-queue to use this new API: https://github.com/dunglas/frankenphp-queue/compare/refactor/ExtensionWorkers?expand=1

WDYT?

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the worker extension API from a registration-based pattern to a functional options pattern, replacing RegisterWorker/NewWorker with WithExtensionWorkers.

  • Replaces the global worker registry approach with direct option passing via Init()
  • Introduces a new Workers interface to provide type-safe access to extension workers
  • Updates the Caddy integration to support the new worker extension API via RegisterWorkers()

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
workerextension.go Refactors Worker struct to Workers interface and extensionWorkers implementation, simplifying API by removing error handling from SendMessage
workerextension_test.go Updates tests to use new WithExtensionWorkers() API pattern and modernizes test cleanup with t.Cleanup()
options.go Adds WithExtensionWorkers() function and moves related options for better organization
worker.go Adds assignment of internalWorker reference during worker creation
frankenphp.go Removes global extensionWorkers registry logic from Init()
caddy/app.go Adds RegisterWorkers() function with mutex-protected global options to support extensions

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@alexandre-daubois
Copy link
Member

I love how you can provided ini settings and such. Should it be documented somewhere? A new section in the "Writing extensions" doc?

@dunglas
Copy link
Member Author

dunglas commented Oct 31, 2025

Sure, this needs to be documented.

@dunglas
Copy link
Member Author

dunglas commented Oct 31, 2025

Actually, max time exceeded errors was currently hidden and undetectable. I updated the code to return them to the calling Go code. cc @AlliBalliBaba

@dunglas
Copy link
Member Author

dunglas commented Oct 31, 2025

I also changed the error returned when the server is overloaded and refuse request from a 504 "Gateway Timeout" to a 503 "Service Unavailable". It's more appropriate because we're not acting as a proxy but as an application server here.

@dunglas dunglas force-pushed the refactor/ExtensionWorkers branch from a92a05e to 52fde72 Compare November 2, 2025 14:01
Copy link
Member

@alexandre-daubois alexandre-daubois left a comment

Choose a reason for hiding this comment

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

Let's create an issue so we don't forget to document it, if it's not shipped in the PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants