Skip to content

refactor: improve ExtensionWorkers API#1952

Merged
dunglas merged 13 commits into
mainfrom
refactor/ExtensionWorkers
Nov 10, 2025
Merged

refactor: improve ExtensionWorkers API#1952
dunglas merged 13 commits into
mainfrom
refactor/ExtensionWorkers

Conversation

@dunglas

@dunglas dunglas commented Oct 30, 2025

Copy link
Copy Markdown
Member

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?

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread options.go Outdated
Comment thread workerextension.go Outdated
Comment thread workerextension.go Outdated
Comment thread workerextension.go Outdated
Comment thread caddy/app.go Outdated
Comment thread caddy/app.go
Comment thread workerextension.go Outdated
Comment thread caddy/app.go
@alexandre-daubois

Copy link
Copy Markdown
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

dunglas commented Oct 31, 2025

Copy link
Copy Markdown
Member Author

Sure, this needs to be documented.

@dunglas

dunglas commented Oct 31, 2025

Copy link
Copy Markdown
Member Author

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

dunglas commented Oct 31, 2025

Copy link
Copy Markdown
Member Author

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.

Comment thread context.go
Comment thread caddy/caddy_test.go
Comment thread context.go
dunglas and others added 12 commits November 2, 2025 14:58
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@dunglas
dunglas force-pushed the refactor/ExtensionWorkers branch from a92a05e to 52fde72 Compare November 2, 2025 14:01

@alexandre-daubois alexandre-daubois left a comment

Copy link
Copy Markdown
Member

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?

@dunglas
dunglas merged commit 6225da9 into main Nov 10, 2025
24 checks passed
@dunglas
dunglas deleted the refactor/ExtensionWorkers branch November 10, 2025 13:12
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