| Total Complexity | 109 |
| Total Lines | 663 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like ExternalTaskEntity often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ExternalTaskEntity, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 34 | class ExternalTaskEntity implements ExternalTaskInterface, DbEntityInterface, HasDbRevisionInterface, HasDbReferencesInterface |
||
| 35 | { |
||
| 36 | //protected static final EnginePersistenceLogger LOG = ProcessEngineLogger.PERSISTENCE_LOGGER; |
||
| 37 | private const EXCEPTION_NAME = "externalTask.exceptionByteArray"; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Note: String#length() counts Unicode supplementary |
||
| 41 | * characters twice, so for a String consisting only of those, |
||
| 42 | * the limit is effectively MAX_EXCEPTION_MESSAGE_LENGTH / 2 |
||
| 43 | */ |
||
| 44 | public const MAX_EXCEPTION_MESSAGE_LENGTH = 666; |
||
| 45 | |||
| 46 | protected $id; |
||
| 47 | protected $revision; |
||
| 48 | |||
| 49 | protected $topicName; |
||
| 50 | protected $workerId; |
||
| 51 | protected $lockExpirationTime; |
||
| 52 | protected $retries; |
||
| 53 | protected $errorMessage; |
||
| 54 | |||
| 55 | protected $errorDetailsByteArray; |
||
| 56 | protected $errorDetailsByteArrayId; |
||
| 57 | |||
| 58 | protected $suspensionState; |
||
| 59 | protected $executionId; |
||
| 60 | protected $processInstanceId; |
||
| 61 | protected $processDefinitionId; |
||
| 62 | protected $processDefinitionKey; |
||
| 63 | protected $processDefinitionVersionTag; |
||
| 64 | protected $activityId; |
||
| 65 | protected $activityInstanceId; |
||
| 66 | protected $tenantId; |
||
| 67 | protected $priority; |
||
| 68 | |||
| 69 | protected $extensionProperties = []; |
||
| 70 | |||
| 71 | protected $execution; |
||
| 72 | |||
| 73 | protected $businessKey; |
||
| 74 | |||
| 75 | protected $lastFailureLogId; |
||
| 76 | |||
| 77 | public function __construct() |
||
| 78 | { |
||
| 79 | $this->suspensionState = SuspensionState::active()->getStateCode(); |
||
| 80 | } |
||
| 81 | |||
| 82 | public function getId(): ?string |
||
| 83 | { |
||
| 84 | return $this->id; |
||
| 85 | } |
||
| 86 | |||
| 87 | public function setId(string $id): void |
||
| 88 | { |
||
| 89 | $this->id = $id; |
||
| 90 | } |
||
| 91 | |||
| 92 | public function getTopicName(): string |
||
| 93 | { |
||
| 94 | return $this->topicName; |
||
| 95 | } |
||
| 96 | |||
| 97 | public function setTopicName(string $topic): void |
||
| 98 | { |
||
| 99 | $this->topicName = $topic; |
||
| 100 | } |
||
| 101 | |||
| 102 | public function getWorkerId(): string |
||
| 103 | { |
||
| 104 | return $this->workerId; |
||
| 105 | } |
||
| 106 | |||
| 107 | public function setWorkerId(string $workerId): void |
||
| 108 | { |
||
| 109 | $this->workerId = $workerId; |
||
| 110 | } |
||
| 111 | |||
| 112 | public function getLockExpirationTime(): string |
||
| 113 | { |
||
| 114 | return $this->lockExpirationTime; |
||
| 115 | } |
||
| 116 | |||
| 117 | public function setLockExpirationTime(string $lockExpirationTime): void |
||
| 118 | { |
||
| 119 | $this->lockExpirationTime = $lockExpirationTime; |
||
| 120 | } |
||
| 121 | |||
| 122 | public function getExecutionId(): string |
||
| 123 | { |
||
| 124 | return $this->executionId; |
||
| 125 | } |
||
| 126 | |||
| 127 | public function setExecutionId(string $executionId): void |
||
| 128 | { |
||
| 129 | $this->executionId = $executionId; |
||
| 130 | } |
||
| 131 | |||
| 132 | public function getProcessDefinitionKey(): string |
||
| 133 | { |
||
| 134 | return $this->processDefinitionKey; |
||
| 135 | } |
||
| 136 | |||
| 137 | public function setProcessDefinitionKey(string $processDefinitionKey): void |
||
| 138 | { |
||
| 139 | $this->processDefinitionKey = $processDefinitionKey; |
||
| 140 | } |
||
| 141 | |||
| 142 | public function getProcessDefinitionVersionTag(): string |
||
| 143 | { |
||
| 144 | return $this->processDefinitionVersionTag; |
||
| 145 | } |
||
| 146 | |||
| 147 | public function setProcessDefinitionVersionTag(string $processDefinitionVersionTag): void |
||
| 148 | { |
||
| 149 | $this->processDefinitionVersionTag = $processDefinitionVersionTag; |
||
| 150 | } |
||
| 151 | |||
| 152 | public function getActivityId(): string |
||
| 153 | { |
||
| 154 | return $this->activityId; |
||
| 155 | } |
||
| 156 | |||
| 157 | public function setActivityId(string $activityId): void |
||
| 158 | { |
||
| 159 | $this->activityId = $activityId; |
||
| 160 | } |
||
| 161 | |||
| 162 | public function getActivityInstanceId(): string |
||
| 163 | { |
||
| 164 | return $this->activityInstanceId; |
||
| 165 | } |
||
| 166 | |||
| 167 | public function setActivityInstanceId(string $activityInstanceId): void |
||
| 168 | { |
||
| 169 | $this->activityInstanceId = $activityInstanceId; |
||
| 170 | } |
||
| 171 | |||
| 172 | public function getRevision(): int |
||
| 173 | { |
||
| 174 | return $this->revision; |
||
| 175 | } |
||
| 176 | |||
| 177 | public function setRevision(int $revision): void |
||
| 178 | { |
||
| 179 | $this->revision = $revision; |
||
| 180 | } |
||
| 181 | |||
| 182 | public function getRevisionNext(): int |
||
| 183 | { |
||
| 184 | return $this->revision + 1; |
||
| 185 | } |
||
| 186 | |||
| 187 | public function getSuspensionState(): int |
||
| 188 | { |
||
| 189 | return $this->suspensionState; |
||
| 190 | } |
||
| 191 | |||
| 192 | public function setSuspensionState(int $suspensionState): void |
||
| 193 | { |
||
| 194 | $this->suspensionState = $suspensionState; |
||
| 195 | } |
||
| 196 | |||
| 197 | public function isSuspended(): bool |
||
| 198 | { |
||
| 199 | return $this->suspensionState == SuspensionState::suspended()->getStateCode(); |
||
| 200 | } |
||
| 201 | |||
| 202 | public function getProcessInstanceId(): string |
||
| 203 | { |
||
| 204 | return $this->processInstanceId; |
||
| 205 | } |
||
| 206 | |||
| 207 | public function setProcessInstanceId(string $processInstanceId): void |
||
| 208 | { |
||
| 209 | $this->processInstanceId = $processInstanceId; |
||
| 210 | } |
||
| 211 | |||
| 212 | public function getProcessDefinitionId(): string |
||
| 213 | { |
||
| 214 | return $this->processDefinitionId; |
||
| 215 | } |
||
| 216 | |||
| 217 | public function setProcessDefinitionId(string $processDefinitionId): void |
||
| 218 | { |
||
| 219 | $this->processDefinitionId = $processDefinitionId; |
||
| 220 | } |
||
| 221 | |||
| 222 | public function getTenantId(): ?string |
||
| 223 | { |
||
| 224 | return $this->tenantId; |
||
| 225 | } |
||
| 226 | |||
| 227 | public function setTenantId(?string $tenantId): void |
||
| 228 | { |
||
| 229 | $this->tenantId = $tenantId; |
||
| 230 | } |
||
| 231 | |||
| 232 | public function getRetries(): int |
||
| 233 | { |
||
| 234 | return $this->retries; |
||
| 235 | } |
||
| 236 | |||
| 237 | public function setRetries(int $retries): void |
||
| 238 | { |
||
| 239 | $this->retries = $retries; |
||
| 240 | } |
||
| 241 | |||
| 242 | public function getErrorMessage(): string |
||
| 243 | { |
||
| 244 | return $this->errorMessage; |
||
| 245 | } |
||
| 246 | |||
| 247 | public function areRetriesLeft(): bool |
||
| 248 | { |
||
| 249 | return $this->retries === null || $this->retries > 0; |
||
| 250 | } |
||
| 251 | |||
| 252 | public function getPriority(): int |
||
| 253 | { |
||
| 254 | return $this->priority; |
||
| 255 | } |
||
| 256 | |||
| 257 | public function setPriority(int $priority): void |
||
| 258 | { |
||
| 259 | $this->priority = $priority; |
||
| 260 | } |
||
| 261 | |||
| 262 | public function getBusinessKey(): ?string |
||
| 263 | { |
||
| 264 | return $this->businessKey; |
||
| 265 | } |
||
| 266 | |||
| 267 | public function setBusinessKey(string $businessKey): void |
||
| 268 | { |
||
| 269 | $this->businessKey = $businessKey; |
||
| 270 | } |
||
| 271 | |||
| 272 | public function getExtensionProperties(): array |
||
| 273 | { |
||
| 274 | return $this->extensionProperties; |
||
| 275 | } |
||
| 276 | |||
| 277 | public function setExtensionProperties(array $extensionProperties): void |
||
| 278 | { |
||
| 279 | $this->extensionProperties = $extensionProperties; |
||
| 280 | } |
||
| 281 | |||
| 282 | public function getPersistentState() |
||
| 283 | { |
||
| 284 | $persistentState = []; |
||
| 285 | $persistentState["topic"] = $this->topicName; |
||
| 286 | $persistentState["workerId"] = $this->workerId; |
||
| 287 | $persistentState["lockExpirationTime"] = $this->lockExpirationTime; |
||
| 288 | $persistentState["retries"] = $this->retries; |
||
| 289 | $persistentState["errorMessage"] = $this->errorMessage; |
||
| 290 | $persistentState["executionId"] = $this->executionId; |
||
| 291 | $persistentState["processInstanceId"] = $this->processInstanceId; |
||
| 292 | $persistentState["processDefinitionId"] = $this->processDefinitionId; |
||
| 293 | $persistentState["processDefinitionKey"] = $this->processDefinitionKey; |
||
| 294 | $persistentState["processDefinitionVersionTag"] = $this->processDefinitionVersionTag; |
||
| 295 | $persistentState["activityId"] = $this->activityId; |
||
| 296 | $persistentState["activityInstanceId"] = $this->activityInstanceId; |
||
| 297 | $persistentState["suspensionState"] = $this->suspensionState; |
||
| 298 | $persistentState["tenantId"] = $this->tenantId; |
||
| 299 | $persistentState["priority"] = $this->priority; |
||
| 300 | |||
| 301 | if ($this->errorDetailsByteArrayId !== null) { |
||
| 302 | $persistentState["errorDetailsByteArrayId"] = $this->errorDetailsByteArrayId; |
||
| 303 | } |
||
| 304 | |||
| 305 | return $persistentState; |
||
| 306 | } |
||
| 307 | |||
| 308 | public function insert(): void |
||
| 309 | { |
||
| 310 | Context::getCommandContext() |
||
| 311 | ->getExternalTaskManager() |
||
| 312 | ->insert($this); |
||
| 313 | |||
| 314 | $this->getExecution()->addExternalTask($this); |
||
| 315 | } |
||
| 316 | |||
| 317 | /** |
||
| 318 | * Method implementation relies on the command context object, |
||
| 319 | * therefore should be invoked from the commands only |
||
| 320 | * |
||
| 321 | * @return string error details persisted in byte array table |
||
| 322 | */ |
||
| 323 | public function getErrorDetails(): string |
||
| 324 | { |
||
| 325 | $byteArray = $this->getErrorByteArray(); |
||
| 326 | return ExceptionUtil::getExceptionStacktrace($byteArray); |
||
| 327 | } |
||
| 328 | |||
| 329 | public function setErrorMessage(string $errorMessage): void |
||
| 330 | { |
||
| 331 | if ($errorMessage !== null && strlen($errorMessage) > self::MAX_EXCEPTION_MESSAGE_LENGTH) { |
||
| 332 | $this->errorMessage = substr($errorMessage, 0, self::MAX_EXCEPTION_MESSAGE_LENGTH); |
||
| 333 | } else { |
||
| 334 | $this->errorMessage = $errorMessage; |
||
| 335 | } |
||
| 336 | } |
||
| 337 | |||
| 338 | protected function setErrorDetails(string $exception): void |
||
| 339 | { |
||
| 340 | EnsureUtil::ensureNotNull("exception", "exception", $exception); |
||
| 341 | |||
| 342 | $exceptionBytes = StringUtil::toByteArray($exception); |
||
| 343 | |||
| 344 | $byteArray = $this->getErrorByteArray(); |
||
| 345 | |||
| 346 | if ($byteArray === null) { |
||
| 347 | $byteArray = ExceptionUtil::createExceptionByteArray(self::EXCEPTION_NAME, $exceptionBytes, ResourceTypes::runtime()); |
||
| 348 | $this->errorDetailsByteArrayId = $byteArray->getId(); |
||
| 349 | $this->errorDetailsByteArray = $byteArray; |
||
| 350 | } else { |
||
| 351 | $byteArray->setBytes($exceptionBytes); |
||
| 352 | } |
||
| 353 | } |
||
| 354 | |||
| 355 | public function getErrorDetailsByteArrayId(): string |
||
| 356 | { |
||
| 357 | return $this->errorDetailsByteArrayId; |
||
| 358 | } |
||
| 359 | |||
| 360 | protected function getErrorByteArray(): ByteArrayEntity |
||
| 361 | { |
||
| 362 | $this->ensureErrorByteArrayInitialized(); |
||
| 363 | return $this->errorDetailsByteArray; |
||
| 364 | } |
||
| 365 | |||
| 366 | protected function ensureErrorByteArrayInitialized(): void |
||
| 367 | { |
||
| 368 | if (empty($this->errorDetailsByteArray) && $this->errorDetailsByteArrayId !== null) { |
||
| 369 | $this->errorDetailsByteArray = Context::getCommandContext() |
||
| 370 | ->getDbEntityManager() |
||
| 371 | ->selectById(ByteArrayEntity::class, $this->errorDetailsByteArrayId); |
||
| 372 | } |
||
| 373 | } |
||
| 374 | |||
| 375 | public function delete(): void |
||
| 376 | { |
||
| 377 | $this->deleteFromExecutionAndRuntimeTable(false); |
||
| 378 | $this->produceHistoricExternalTaskDeletedEvent(); |
||
| 379 | } |
||
| 380 | |||
| 381 | protected function deleteFromExecutionAndRuntimeTable(bool $incidentResolved): void |
||
| 382 | { |
||
| 383 | $this->getExecution()->removeExternalTask($this); |
||
| 384 | |||
| 385 | $commandContext = Context::getCommandContext(); |
||
| 386 | |||
| 387 | $commandContext |
||
| 388 | ->getExternalTaskManager() |
||
| 389 | ->delete($this); |
||
| 390 | |||
| 391 | // Also delete the external tasks's error details byte array |
||
| 392 | if ($this->errorDetailsByteArrayId !== null) { |
||
| 393 | $commandContext->getByteArrayManager()->deleteByteArrayById($this->errorDetailsByteArrayId); |
||
| 394 | } |
||
| 395 | |||
| 396 | $this->removeIncidents($incidentResolved); |
||
| 397 | } |
||
| 398 | |||
| 399 | protected function removeIncidents(bool $incidentResolved): void |
||
| 400 | { |
||
| 401 | $incidentContext = $this->createIncidentContext(); |
||
| 402 | IncidentHandling::removeIncidents(IncidentInterface::EXTERNAL_TASK_HANDLER_TYPE, $incidentContext, $incidentResolved); |
||
| 403 | } |
||
| 404 | |||
| 405 | public function complete(array $variables, array $localVariables): void |
||
| 406 | { |
||
| 407 | $this->ensureActive(); |
||
| 408 | |||
| 409 | $associatedExecution = $this->getExecution(); |
||
| 410 | |||
| 411 | $this->ensureVariablesSet($associatedExecution, $variables, $localVariables); |
||
| 412 | |||
| 413 | if ($this->evaluateThrowBpmnError($associatedExecution, false)) { |
||
| 414 | return; |
||
| 415 | } |
||
| 416 | |||
| 417 | $this->deleteFromExecutionAndRuntimeTable(true); |
||
| 418 | |||
| 419 | $this->produceHistoricExternalTaskSuccessfulEvent(); |
||
| 420 | |||
| 421 | $associatedExecution->signal(null, null); |
||
|
|
|||
| 422 | } |
||
| 423 | |||
| 424 | /** |
||
| 425 | * process failed state, make sure that binary entity is created for the errorMessage, shortError |
||
| 426 | * message does not exceed limit, handle properly retry counts and incidents |
||
| 427 | * |
||
| 428 | * @param errorMessage short error message text |
||
| 429 | * @param errorDetails full error details |
||
| 430 | * @param retries updated value of retries left |
||
| 431 | * @param retryDuration used for lockExpirationTime calculation |
||
| 432 | */ |
||
| 433 | public function failed(string $errorMessage, string $errorDetails, int $retries, int $retryDuration, array $variables, array $localVariables): void |
||
| 434 | { |
||
| 435 | $this->ensureActive(); |
||
| 436 | |||
| 437 | $associatedExecution = $this->getExecution(); |
||
| 438 | |||
| 439 | $this->ensureVariablesSet($this->execution, $variables, $localVariables); |
||
| 440 | |||
| 441 | $this->setErrorMessage($errorMessage); |
||
| 442 | |||
| 443 | if (!empty($errorDetails)) { |
||
| 444 | $this->setErrorDetails($errorDetails); |
||
| 445 | } |
||
| 446 | |||
| 447 | if ($this->evaluateThrowBpmnError($associatedExecution, true)) { |
||
| 448 | return; |
||
| 449 | } |
||
| 450 | $dt = new \DateTime(); |
||
| 451 | $dt->setTimestamp(ClockUtil::getCurrentTime()->getTimestamp() + $retryDuration); |
||
| 452 | $this->lockExpirationTime = $dt->format('c'); |
||
| 453 | $this->produceHistoricExternalTaskFailedEvent(); |
||
| 454 | $this->setRetriesAndManageIncidents($retries); |
||
| 455 | } |
||
| 456 | |||
| 457 | public function bpmnError(string $errorCode, string $errorMessage, array $variables): void |
||
| 458 | { |
||
| 459 | $this->ensureActive(); |
||
| 460 | $activityExecution = $this->getExecution(); |
||
| 461 | $bpmnError = null; |
||
| 462 | if ($errorMessage !== null) { |
||
| 463 | $bpmnError = new BpmnError($errorCode, $errorMessage); |
||
| 464 | } else { |
||
| 465 | $bpmnError = new BpmnError($errorCode); |
||
| 466 | } |
||
| 467 | try { |
||
| 468 | if (!empty($variables)) { |
||
| 469 | $activityExecution->setVariables($variables); |
||
| 470 | } |
||
| 471 | BpmnExceptionHandler::propagateBpmnError($bpmnError, $activityExecution); |
||
| 472 | } catch (\Exception $ex) { |
||
| 473 | //throw ProcessEngineLogger.CMD_LOGGER.exceptionBpmnErrorPropagationFailed(errorCode, ex); |
||
| 474 | throw $ex; |
||
| 475 | } |
||
| 476 | } |
||
| 477 | |||
| 478 | public function setRetriesAndManageIncidents(int $retries): void |
||
| 479 | { |
||
| 480 | |||
| 481 | if ($this->areRetriesLeft() && $this->retries <= 0) { |
||
| 482 | $this->createIncident(); |
||
| 483 | } elseif (!$this->areRetriesLeft() && $this->retries > 0) { |
||
| 484 | $this->removeIncidents(true); |
||
| 485 | } |
||
| 486 | |||
| 487 | $this->setRetries($this->retries); |
||
| 488 | } |
||
| 489 | |||
| 490 | protected function createIncident(): void |
||
| 491 | { |
||
| 492 | $incidentContext = $this->createIncidentContext(); |
||
| 493 | $incidentContext->setHistoryConfiguration($this->getLastFailureLogId()); |
||
| 494 | |||
| 495 | IncidentHandling::createIncident(IncidentInterface::EXTERNAL_TASK_HANDLER_TYPE, $incidentContext, $this->errorMessage); |
||
| 496 | } |
||
| 497 | |||
| 498 | protected function createIncidentContext(): IncidentContext |
||
| 499 | { |
||
| 500 | $context = new IncidentContext(); |
||
| 501 | $context->setProcessDefinitionId($this->processDefinitionId); |
||
| 502 | $context->setExecutionId($this->executionId); |
||
| 503 | $context->setActivityId($this->activityId); |
||
| 504 | $context->setTenantId($this->tenantId); |
||
| 505 | $context->setConfiguration($this->id); |
||
| 506 | return $context; |
||
| 507 | } |
||
| 508 | |||
| 509 | public function lock(string $workerId, int $lockDuration): void |
||
| 510 | { |
||
| 511 | $this->workerId = $workerId; |
||
| 512 | $dt = new \DateTime(); |
||
| 513 | $dt->setTimestamp(ClockUtil::getCurrentTime()->getTimestamp() + $lockDuration); |
||
| 514 | $this->lockExpirationTime = $dt->format('c'); |
||
| 515 | } |
||
| 516 | |||
| 517 | public function getExecution(?bool $validateExistence = true): ExecutionEntity |
||
| 518 | { |
||
| 519 | $this->ensureExecutionInitialized($validateExistence); |
||
| 520 | return $this->execution; |
||
| 521 | } |
||
| 522 | |||
| 523 | public function setExecution(ExecutionEntity $execution): void |
||
| 524 | { |
||
| 525 | $this->execution = $execution; |
||
| 526 | } |
||
| 527 | |||
| 528 | protected function ensureExecutionInitialized(bool $validateExistence): void |
||
| 529 | { |
||
| 530 | if ($this->execution === null) { |
||
| 531 | $execution = Context::getCommandContext()->getExecutionManager()->findExecutionById($this->executionId); |
||
| 532 | |||
| 533 | if ($validateExistence) { |
||
| 534 | EnsureUtil::ensureNotNull( |
||
| 535 | "Cannot find execution with id " . $this->executionId . " for external task " . $this->id, |
||
| 536 | "execution", |
||
| 537 | $execution |
||
| 538 | ); |
||
| 539 | } |
||
| 540 | } |
||
| 541 | } |
||
| 542 | |||
| 543 | protected function ensureActive(): void |
||
| 544 | { |
||
| 545 | if ($this->suspensionState == SuspensionState::suspended()->getStateCode()) { |
||
| 546 | //throw LOG.suspendedEntityException(EntityTypes.EXTERNAL_TASK, id); |
||
| 547 | throw new \Exception("Execution"); |
||
| 548 | } |
||
| 549 | } |
||
| 550 | |||
| 551 | protected function ensureVariablesSet(ExecutionEntity $execution, array $variables, array $localVariables): void |
||
| 552 | { |
||
| 553 | if (!empty($variables)) { |
||
| 554 | $execution->setVariables($variables); |
||
| 555 | } |
||
| 556 | |||
| 557 | if (!empty($localVariables)) { |
||
| 558 | $execution->setVariablesLocal($localVariables); |
||
| 559 | } |
||
| 560 | } |
||
| 561 | |||
| 562 | protected function evaluateThrowBpmnError(ExecutionEntity $execution, bool $continueOnException): bool |
||
| 563 | { |
||
| 564 | $errorEventDefinitions = $execution->getActivity()->getProperty(BpmnProperties::errorEventDefinition()->getName()); |
||
| 565 | if (!empty($errorEventDefinitions)) { |
||
| 566 | foreach ($errorEventDefinitions as $errorEventDefinition) { |
||
| 567 | if ($this->errorEventDefinitionMatches($errorEventDefinition, $continueOnException)) { |
||
| 568 | $this->bpmnError($errorEventDefinition->getErrorCode(), $this->errorMessage, null); |
||
| 569 | return true; |
||
| 570 | } |
||
| 571 | } |
||
| 572 | } |
||
| 573 | return false; |
||
| 574 | } |
||
| 575 | |||
| 576 | protected function errorEventDefinitionMatches(ErrorEventDefinition $errorEventDefinition, bool $continueOnException): bool |
||
| 577 | { |
||
| 578 | try { |
||
| 579 | return $errorEventDefinition->getExpression() !== null && $errorEventDefinition->getExpression()->getValue($this->getExecution()) == true; |
||
| 580 | } catch (\Exception $exception) { |
||
| 581 | if ($continueOnException) { |
||
| 582 | //ProcessEngineLogger.EXTERNAL_TASK_LOGGER.errorEventDefinitionEvaluationException(id, camundaErrorEventDefinition, exception); |
||
| 583 | return false; |
||
| 584 | } |
||
| 585 | throw $exception; |
||
| 586 | } |
||
| 587 | } |
||
| 588 | |||
| 589 | public function __toString() |
||
| 590 | { |
||
| 591 | return "ExternalTaskEntity [" |
||
| 592 | . "id=" . $this->id |
||
| 593 | . ", revision=" . $this->revision |
||
| 594 | . ", topicName=" . $this->topicName |
||
| 595 | . ", workerId=" . $this->workerId |
||
| 596 | . ", lockExpirationTime=" . $this->lockExpirationTime |
||
| 597 | . ", priority=" . $this->priority |
||
| 598 | . ", errorMessage=" . $this->errorMessage |
||
| 599 | . ", errorDetailsByteArray=" . $this->errorDetailsByteArray |
||
| 600 | . ", errorDetailsByteArrayId=" . $this->errorDetailsByteArrayId |
||
| 601 | . ", executionId=" . $this->executionId . "]"; |
||
| 602 | } |
||
| 603 | |||
| 604 | public function unlock(): void |
||
| 605 | { |
||
| 606 | $this->workerId = null; |
||
| 607 | $this->lockExpirationTime = null; |
||
| 608 | |||
| 609 | Context::getCommandContext() |
||
| 610 | ->getExternalTaskManager() |
||
| 611 | ->fireExternalTaskAvailableEvent(); |
||
| 612 | } |
||
| 613 | |||
| 614 | public static function createAndInsert(ExecutionEntity $execution, string $topic, int $priority): ExternalTaskEntity |
||
| 634 | } |
||
| 635 | |||
| 636 | protected function produceHistoricExternalTaskCreatedEvent(): void |
||
| 637 | { |
||
| 638 | $commandContext = Context::getCommandContext(); |
||
| 639 | $commandContext->getHistoricExternalTaskLogManager()->fireExternalTaskCreatedEvent($this); |
||
| 640 | } |
||
| 641 | |||
| 642 | protected function produceHistoricExternalTaskFailedEvent(): void |
||
| 643 | { |
||
| 644 | $commandContext = Context::getCommandContext(); |
||
| 645 | $commandContext->getHistoricExternalTaskLogManager()->fireExternalTaskFailedEvent($this); |
||
| 646 | } |
||
| 647 | |||
| 648 | protected function produceHistoricExternalTaskSuccessfulEvent(): void |
||
| 649 | { |
||
| 650 | $commandContext = Context::getCommandContext(); |
||
| 651 | $commandContext->getHistoricExternalTaskLogManager()->fireExternalTaskSuccessfulEvent($this); |
||
| 652 | } |
||
| 653 | |||
| 654 | protected function produceHistoricExternalTaskDeletedEvent(): void |
||
| 655 | { |
||
| 656 | $commandContext = Context::getCommandContext(); |
||
| 657 | $commandContext->getHistoricExternalTaskLogManager()->fireExternalTaskDeletedEvent($this); |
||
| 658 | } |
||
| 659 | |||
| 660 | public function extendLock(int $newLockExpirationTime): void |
||
| 661 | { |
||
| 662 | $this->ensureActive(); |
||
| 663 | $dt = new \DateTime(); |
||
| 664 | $dt->setTimestamp(ClockUtil::getCurrentTime()->getTimestamp() + $newLockExpirationTime); |
||
| 665 | $newTime = $dt->format('c'); |
||
| 666 | $this->lockExpirationTime = $newTime; |
||
| 667 | } |
||
| 668 | |||
| 669 | public function getReferencedEntityIds(): array |
||
| 673 | } |
||
| 674 | |||
| 675 | public function getReferencedEntitiesIdAndClass(): array |
||
| 676 | { |
||
| 677 | $referenceIdAndClass = []; |
||
| 678 | |||
| 679 | if ($this->executionId !== null) { |
||
| 687 | } |
||
| 688 | |||
| 689 | public function getLastFailureLogId(): ?string |
||
| 690 | { |
||
| 691 | return $this->lastFailureLogId; |
||
| 692 | } |
||
| 693 | |||
| 694 | public function setLastFailureLogId(string $lastFailureLogId): void |
||
| 695 | { |
||
| 696 | $this->lastFailureLogId = $lastFailureLogId; |
||
| 697 | } |
||
| 698 | } |
||
| 699 |