|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Jabe\Engine\Impl; |
|
4
|
|
|
|
|
5
|
|
|
use Jabe\Engine\ExternalTaskServiceInterface; |
|
6
|
|
|
use Jabe\Engine\Batch\BatchInterface; |
|
7
|
|
|
use Jabe\Engine\ExternalTask\{ |
|
8
|
|
|
ExternalTaskQueryInterface, |
|
9
|
|
|
ExternalTaskQueryBuilderInterface, |
|
10
|
|
|
UpdateExternalTaskRetriesSelectBuilderInterface |
|
11
|
|
|
}; |
|
12
|
|
|
use Jabe\Engine\Impl\Cmd\{ |
|
13
|
|
|
LockExternalTaskCmd, |
|
14
|
|
|
CompleteExternalTaskCmd, |
|
15
|
|
|
HandleExternalTaskFailureCmd, |
|
16
|
|
|
HandleExternalTaskBpmnErrorCmd, |
|
17
|
|
|
UnlockExternalTaskCmd, |
|
18
|
|
|
SetExternalTaskRetriesCmd, |
|
19
|
|
|
SetExternalTaskPriorityCmd, |
|
20
|
|
|
GetTopicNamesCmd, |
|
21
|
|
|
GetExternalTaskErrorDetailsCmd, |
|
22
|
|
|
ExtendLockOnExternalTaskCmd |
|
23
|
|
|
}; |
|
24
|
|
|
use Jabe\Engine\Impl\ExternalTask\ExternalTaskQueryTopicBuilderImpl; |
|
25
|
|
|
|
|
26
|
|
|
class ExternalTaskServiceImpl extends ServiceImpl implements ExternalTaskServiceInterface |
|
27
|
|
|
{ |
|
28
|
|
|
public function fetchAndLock(int $maxTasks, string $workerId, bool $usePriority = false): ExternalTaskQueryBuilderInterface |
|
29
|
|
|
{ |
|
30
|
|
|
return new ExternalTaskQueryTopicBuilderImpl($this->commandExecutor, $workerId, $maxTasks, $usePriority); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function lock(string $externalTaskId, string $workerId, int $lockDuration): void |
|
34
|
|
|
{ |
|
35
|
|
|
$this->commandExecutor->execute(new LockExternalTaskCmd($externalTaskId, $workerId, $lockDuration)); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function complete(string $externalTaskId, string $workerId, array $variables = [], array $localVariables = []): void |
|
39
|
|
|
{ |
|
40
|
|
|
$this->commandExecutor->execute(new CompleteExternalTaskCmd($externalTaskId, $workerId, $variables, $localVariables)); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function handleFailure(string $externalTaskId, string $workerId, string $errorMessage, string $errorDetails, int $retries, int $retryDuration, array $variables = [], array $localVariables = []): void |
|
44
|
|
|
{ |
|
45
|
|
|
$this->commandExecutor->execute(new HandleExternalTaskFailureCmd(externalTaskId, workerId, errorMessage, errorDetails, retries, retryDuration, variables, localVariables)); |
|
|
|
|
|
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function handleBpmnError(string $externalTaskId, string $workerId, string $errorCode, string $errorMessage = null, array $variables = []): void |
|
49
|
|
|
{ |
|
50
|
|
|
$this->commandExecutor->execute(new HandleExternalTaskBpmnErrorCmd($externalTaskId, $workerId, $errorCode, $errorMessage, $variables)); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function unlock(string $externalTaskId): void |
|
54
|
|
|
{ |
|
55
|
|
|
$this->commandExecutor->execute(new UnlockExternalTaskCmd($externalTaskId)); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function setPriority(string $externalTaskId, int $priority): void |
|
59
|
|
|
{ |
|
60
|
|
|
$this->commandExecutor->execute(new SetExternalTaskPriorityCmd($externalTaskId, $priority)); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function createExternalTaskQuery(): ExternalTaskQueryInterface |
|
64
|
|
|
{ |
|
65
|
|
|
return new ExternalTaskQueryImpl($this->commandExecutor); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function getTopicNames(bool $withLockedTasks = false, bool $withUnlockedTasks = false, bool $withRetriesLeft = false): array |
|
69
|
|
|
{ |
|
70
|
|
|
return $this->commandExecutor->execute(new GetTopicNamesCmd($withLockedTasks, $withUnlockedTasks, $withRetriesLeft)); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function getExternalTaskErrorDetails(string $externalTaskId): string |
|
74
|
|
|
{ |
|
75
|
|
|
return $this->commandExecutor->execute(new GetExternalTaskErrorDetailsCmd($externalTaskId)); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function setRetries($externalTaskIdOrIds, int $retries, bool $writeUserOperationLog = true): void |
|
79
|
|
|
{ |
|
80
|
|
|
if (is_array($externalTaskIdOrIds)) { |
|
81
|
|
|
$this->updateRetries() |
|
82
|
|
|
->externalTaskIds($externalTaskIdOrIds) |
|
|
|
|
|
|
83
|
|
|
->set($retries); |
|
84
|
|
|
} else { |
|
85
|
|
|
$this->commandExecutor->execute(new SetExternalTaskRetriesCmd($externalTaskIdOrIds, $retries, $writeUserOperationLog)); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function setRetriesAsync(array $externalTaskIds, ExternalTaskQueryInterface $externalTaskQuery, int $retries): BatchInterface |
|
90
|
|
|
{ |
|
91
|
|
|
return $this->updateRetries() |
|
92
|
|
|
->externalTaskIds($externalTaskIds) |
|
93
|
|
|
->externalTaskQuery($externalTaskQuery) |
|
94
|
|
|
->setAsync($retries); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
public function updateRetries(): UpdateExternalTaskRetriesSelectBuilderInterface |
|
98
|
|
|
{ |
|
99
|
|
|
return new UpdateExternalTaskRetriesBuilderImpl($commandExecutor); |
|
|
|
|
|
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
public function extendLock(string $externalTaskId, string $workerId, int $lockDuration): void |
|
103
|
|
|
{ |
|
104
|
|
|
$this->commandExecutor->execute(new ExtendLockOnExternalTaskCmd($externalTaskId, $workerId, $lockDuration)); |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|