Worker
in package
FinalYes
Managed synchronous remote worker for workflow, activity, query, and update tasks.
Table of Contents
Properties
- $taskQueue : string
- $activities : array<string, callable(ActivityContext, mixed ...$arguments): mixed>
- $buildId : string|null
- $client : Client
- $heartbeatIntervalSeconds : int
- $lastHeartbeatAt : float
- $queries : array<string, array<string, callable(QueryContext, mixed ...$arguments): mixed>>
- $replayer : Replayer
- $shutdownRequested : bool
- $updates : array<string, array<string, callable(QueryContext, mixed ...$arguments): mixed>>
- $workerId : string
- $workflows : array<string, callable(WorkflowContext, mixed ...$arguments): mixed>
Methods
- __construct() : mixed
- registerActivity() : self
- registerQuery() : self
- registerUpdate() : self
- registerWorkflow() : self
- requestShutdown() : void
- run() : void
- tick() : bool
- Execute at most one task of each kind; useful for custom supervisors and tests.
- assertUnique() : void
- completeHistory() : array<int, array<string, mixed>>
- decodeArguments() : array<int, mixed>
- executeActivityTask() : void
- executeQueryTask() : void
- executeUpdate() : array<string, mixed>
- executeWorkflowTask() : void
- heartbeatIfDue() : void
- historyFromTask() : array<int, array<string, mixed>>
- installSignalHandlers() : void
Properties
$taskQueue read-only
public
string
$taskQueue
$activities
private
array<string, callable(ActivityContext, mixed ...$arguments): mixed>
$activities
= []
$buildId read-only
private
string|null
$buildId
= null
$client read-only
private
Client
$client
$heartbeatIntervalSeconds read-only
private
int
$heartbeatIntervalSeconds
= 30
$lastHeartbeatAt
private
float
$lastHeartbeatAt
= 0.0
$queries
private
array<string, array<string, callable(QueryContext, mixed ...$arguments): mixed>>
$queries
= []
$replayer read-only
private
Replayer
$replayer
$shutdownRequested
private
bool
$shutdownRequested
= false
$updates
private
array<string, array<string, callable(QueryContext, mixed ...$arguments): mixed>>
$updates
= []
$workerId read-only
private
string
$workerId
$workflows
private
array<string, callable(WorkflowContext, mixed ...$arguments): mixed>
$workflows
= []
Methods
__construct()
public
__construct(Client $client, string $taskQueue[, string|null $workerId = null ][, int $heartbeatIntervalSeconds = 30 ][, string|null $buildId = null ]) : mixed
Parameters
- $client : Client
- $taskQueue : string
- $workerId : string|null = null
- $heartbeatIntervalSeconds : int = 30
- $buildId : string|null = null
registerActivity()
public
registerActivity(string $activityType, callable(ActivityContext, mixed ...$arguments): mixed $handler) : self
Parameters
- $activityType : string
- $handler : callable(ActivityContext, mixed ...$arguments): mixed
Return values
selfregisterQuery()
public
registerQuery(string $workflowType, string $queryName, callable(QueryContext, mixed ...$arguments): mixed $handler) : self
Parameters
- $workflowType : string
- $queryName : string
- $handler : callable(QueryContext, mixed ...$arguments): mixed
Return values
selfregisterUpdate()
public
registerUpdate(string $workflowType, string $updateName, callable(QueryContext, mixed ...$arguments): mixed $handler) : self
Parameters
- $workflowType : string
- $updateName : string
- $handler : callable(QueryContext, mixed ...$arguments): mixed
Return values
selfregisterWorkflow()
public
registerWorkflow(string $workflowType, callable(WorkflowContext, mixed ...$arguments): mixed $handler) : self
Parameters
- $workflowType : string
- $handler : callable(WorkflowContext, mixed ...$arguments): mixed
Return values
selfrequestShutdown()
public
requestShutdown() : void
run()
public
run([int $pollTimeoutSeconds = 5 ]) : void
Parameters
- $pollTimeoutSeconds : int = 5
tick()
Execute at most one task of each kind; useful for custom supervisors and tests.
public
tick([int $pollTimeoutSeconds = 1 ]) : bool
Parameters
- $pollTimeoutSeconds : int = 1
Return values
boolassertUnique()
private
assertUnique(array<string, mixed> $registry, string $name, string $kind) : void
Parameters
- $registry : array<string, mixed>
- $name : string
- $kind : string
completeHistory()
private
completeHistory(array<string, mixed> $task, string $leaseOwner, int $attempt) : array<int, array<string, mixed>>
Parameters
- $task : array<string, mixed>
- $leaseOwner : string
- $attempt : int
Return values
array<int, array<string, mixed>>decodeArguments()
private
decodeArguments(mixed $raw) : array<int, mixed>
Parameters
- $raw : mixed
Return values
array<int, mixed>executeActivityTask()
private
executeActivityTask(array<string, mixed> $task) : void
Parameters
- $task : array<string, mixed>
executeQueryTask()
private
executeQueryTask(array<string, mixed> $task) : void
Parameters
- $task : array<string, mixed>
executeUpdate()
private
executeUpdate(string $workflowType, string $updateId, array<int, array<string, mixed>> $history, array<string, mixed> $task) : array<string, mixed>
Parameters
- $workflowType : string
- $updateId : string
- $history : array<int, array<string, mixed>>
- $task : array<string, mixed>
Return values
array<string, mixed>executeWorkflowTask()
private
executeWorkflowTask(array<string, mixed> $task) : void
Parameters
- $task : array<string, mixed>
heartbeatIfDue()
private
heartbeatIfDue() : void
historyFromTask()
private
historyFromTask(array<string, mixed> $task) : array<int, array<string, mixed>>
Parameters
- $task : array<string, mixed>
Return values
array<int, array<string, mixed>>installSignalHandlers()
private
installSignalHandlers() : void