Documentation

WorkerInterface extends Identifiable

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

Methods

getActivities()  : iterable<string|int, ActivityPrototype>
Returns list of registered activities.
getOptions()  : WorkerOptions
Returns processing options associated with specific worker task queue.
getWorkflows()  : iterable<string|int, WorkflowPrototype>
Returns list of registered workflow prototypes.
registerActivity()  : self
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()  : self
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.

Methods

getActivities()

Returns list of registered activities.

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

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 ]) : self

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

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) : self
Parameters
$finalizer : Closure
Return values
self

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
Tags
see
WorkerInterface::registerActivity
deprecated

use registerActivity() instead.

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(class-string ...$class) : $this
Parameters
$class : class-string
Return values
$this

        
On this page

Search results