WorkerPluginInterface
extends
PluginInterface
in
Plugin interface for configuring workers and worker factory.
Configuration methods are called in registration order.
Task queue name is available via WorkerInterface::getID().
Table of Contents
Methods
- configureWorker() : void
- Modify worker configuration before the worker is created.
- configureWorkerFactory() : void
- Modify worker factory configuration before it is fully initialized.
- getName() : string
- Unique name identifying this plugin (e.g., "my-org.tracing").
- initializeWorker() : void
- Called after a worker is created, allowing plugins to register workflows, activities, and other components on the worker.
- run() : int
- Wraps the worker factory run lifecycle using chain-of-responsibility.
- runWorker() : PromiseInterface
Methods
configureWorker()
Modify worker configuration before the worker is created.
public
configureWorker(WorkerPluginContext $context, callable(WorkerPluginContext): void $next) : void
Task queue name is available via WorkerPluginContext::getTaskQueue().
Parameters
- $context : WorkerPluginContext
- $next : callable(WorkerPluginContext): void
-
Calls the next plugin or the final hook.
configureWorkerFactory()
Modify worker factory configuration before it is fully initialized.
public
configureWorkerFactory(WorkerFactoryPluginContext $context, callable(WorkerFactoryPluginContext): void $next) : void
Parameters
- $context : WorkerFactoryPluginContext
- $next : callable(WorkerFactoryPluginContext): void
-
Calls the next plugin or the final hook.
getName()
Unique name identifying this plugin (e.g., "my-org.tracing").
public
getName() : string
Used for deduplication and diagnostics.
Return values
stringinitializeWorker()
Called after a worker is created, allowing plugins to register workflows, activities, and other components on the worker.
public
initializeWorker(WorkerInterface $worker, callable(WorkerInterface): void $next) : void
This method is called in forward (registration) order immediately after the worker is created. This is the appropriate place for registrations because it is called before the worker starts polling.
Task queue name is available via WorkerInterface::getID().
Parameters
- $worker : WorkerInterface
- $next : callable(WorkerInterface): void
-
Calls the next plugin or the final hook.
run()
Wraps the worker factory run lifecycle using chain-of-responsibility.
public
run(WorkerFactoryInterface $factory, callable(WorkerFactoryInterface): int $next) : int
Each plugin wraps the next one in the chain. The innermost call executes the actual processing loop. Plugins are chained in registration order: the first registered plugin is the outermost wrapper.
Use this to manage resources, add observability, or handle errors:
public function run(WorkerFactoryInterface $factory, callable $next): int
{
$pool = new ConnectionPool();
try {
return $next($factory);
} finally {
$pool->close();
}
}
Parameters
- $factory : WorkerFactoryInterface
- $next : callable(WorkerFactoryInterface): int
-
Calls the next plugin or the actual run loop.
Return values
intrunWorker()
public
runWorker(callable $handler, ServerRequestInterface $request, array<string|int, mixed> $headers, callable $next) : PromiseInterface
Parameters
- $handler : callable
- $request : ServerRequestInterface
- $headers : array<string|int, mixed>
- $next : callable