Documentation

WorkerPluginInterface extends PluginInterface

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

getName()

Unique name identifying this plugin (e.g., "my-org.tracing").

public getName() : string

Used for deduplication and diagnostics.

Return values
string

initializeWorker()

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
int

        
On this page

Search results