Documentation

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
{@inheritDoc}
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

$router

private RouterInterface $router

$services

private ServiceContainer $services

Methods

getActivities()

Returns list of registered activities.

public getActivities() : iterable<string|int, ActivityPrototype>
Return values
iterable<string|int, ActivityPrototype>

getID()

{@inheritDoc}

public getID() : string
Return values
string

getWorkflows()

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 $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
Return values
WorkerInterface

registerActivityFinalizer()

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
WorkerInterface

registerActivityImplementations()

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
$this

registerWorkflowTypes()

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
$this

createRouter()

protected createRouter() : RouterInterface
Return values
RouterInterface

        
On this page

Search results