Worker
in package
implements
WorkerInterface, EventListenerInterface, DispatcherInterface
uses
EventEmitterTrait
Worker manages the execution of workflows and activities within the single TaskQueue. Activity and Workflow processing will be launched using separate processes.
Table of Contents
Interfaces
- WorkerInterface
- Worker manages the execution of workflows and activities within the single TaskQueue. Activity and Workflow processing will be launched using separate processes.
- EventListenerInterface
- DispatcherInterface
Properties
- $name : string
- $options : WorkerOptions
- $router : RouterInterface
- $rpc : RPCConnectionInterface
- $services : ServiceContainer
Methods
- __construct() : mixed
- dispatch() : PromiseInterface
- getActivities() : iterable<string|int, ActivityPrototype>
- Returns list of registered activities.
- getID() : string
- getOptions() : WorkerOptions
- Returns processing options associated with specific worker task queue.
- getWorkflows() : iterable<string|int, WorkflowPrototype>
- Returns list of registered workflow prototypes.
- registerActivity() : WorkerInterface
- Register an activity via its type or via a factory. When an activity class doesn't require any external dependencies and can be created with a keyword `new`:
- registerActivityFinalizer() : WorkerInterface
- Register activity finalizer which is a callback being called after each activity. This can be used to clean up resources in your application.
- registerActivityImplementations() : $this
- Register one or multiple activity instances to be served by worker task queue. Activity implementation must be stateless.
- registerWorkflowTypes() : $this
- Register one or multiple workflow types to be served by worker. Each workflow implementation is stateful so method expects workflow class names instead of actual instances.
- createRouter() : RouterInterface
Properties
$name
private
string
$name
$options
private
WorkerOptions
$options
$router
private
RouterInterface
$router
$rpc
private
RPCConnectionInterface
$rpc
$services
private
ServiceContainer
$services
Methods
__construct()
public
__construct(string $taskQueue, WorkerOptions $options, ServiceContainer $serviceContainer, RPCConnectionInterface $rpc) : mixed
Parameters
- $taskQueue : string
- $options : WorkerOptions
- $serviceContainer : ServiceContainer
- $rpc : RPCConnectionInterface
dispatch()
public
dispatch(ServerRequestInterface $request, array<string|int, mixed> $headers) : PromiseInterface
Parameters
- $request : ServerRequestInterface
- $headers : array<string|int, mixed>
Return values
PromiseInterfacegetActivities()
Returns list of registered activities.
public
getActivities() : iterable<string|int, ActivityPrototype>
Return values
iterable<string|int, ActivityPrototype>getID()
public
getID() : string
Return values
stringgetOptions()
Returns processing options associated with specific worker task queue.
public
getOptions() : WorkerOptions
Return values
WorkerOptionsgetWorkflows()
Returns list of registered workflow prototypes.
public
getWorkflows() : iterable<string|int, WorkflowPrototype>
Return values
iterable<string|int, WorkflowPrototype>registerActivity()
Register an activity via its type or via a factory. When an activity class doesn't require any external dependencies and can be created with a keyword `new`:
public
registerActivity(string $type[, callable|null $factory = null ]) : WorkerInterface
$worker->registerActivity(MyActivity::class);
In case an activity class requires some external dependencies provide a callback - factory that creates or builds a new activity instance. The factory should be a callable which accepts an instance of ReflectionClass with an activity class which should be created.
$worker->registerActivity(MyActivity::class, fn(ReflectionClass $class) => $container->create($class->getName()));
Parameters
- $type : string
- $factory : callable|null = null
Return values
WorkerInterfaceregisterActivityFinalizer()
Register activity finalizer which is a callback being called after each activity. This can be used to clean up resources in your application.
public
registerActivityFinalizer(Closure $finalizer) : WorkerInterface
Parameters
- $finalizer : Closure
Return values
WorkerInterfaceregisterActivityImplementations()
Register one or multiple activity instances to be served by worker task queue. Activity implementation must be stateless.
public
registerActivityImplementations(object ...$activity) : $this
Parameters
- $activity : object
Return values
$thisregisterWorkflowTypes()
Register one or multiple workflow types to be served by worker. Each workflow implementation is stateful so method expects workflow class names instead of actual instances.
public
registerWorkflowTypes(string ...$class) : $this
Parameters
- $class : string
Return values
$thiscreateRouter()
protected
createRouter() : RouterInterface