| Total Complexity | 117 |
| Total Lines | 719 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like JobEntity 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 JobEntity, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 38 | abstract class JobEntity extends AcquirableJobEntity implements \Serializable, HasDbReferencesInterface, JobInterface, DbEntityInterface, HasDbRevisionInterface, DbEntityLifecycleAwareInterface |
||
| 39 | { |
||
| 40 | //private final static EnginePersistenceLogger LOG = ProcessEngineLogger.PERSISTENCE_LOGGER; |
||
| 41 | |||
| 42 | public const DEFAULT_RETRIES = 3; |
||
| 43 | |||
| 44 | protected $executionId = null; |
||
| 45 | |||
| 46 | protected $processDefinitionId = null; |
||
| 47 | protected $processDefinitionKey = null; |
||
| 48 | |||
| 49 | protected $retries = self::DEFAULT_RETRIES; |
||
| 50 | |||
| 51 | // entity is active by default |
||
| 52 | protected $suspensionState = 1; |
||
| 53 | |||
| 54 | protected $jobHandlerType = null; |
||
| 55 | protected $jobHandlerConfiguration = null; |
||
| 56 | |||
| 57 | protected $exceptionByteArray; |
||
| 58 | protected $exceptionByteArrayId; |
||
| 59 | |||
| 60 | protected $exceptionMessage; |
||
| 61 | |||
| 62 | protected $deploymentId; |
||
| 63 | |||
| 64 | protected $jobDefinitionId; |
||
| 65 | |||
| 66 | protected $priority = DefaultJobPriorityProvider::DEFAULT_PRIORITY; |
||
| 67 | |||
| 68 | protected $tenantId; |
||
| 69 | |||
| 70 | protected $createTime; |
||
| 71 | |||
| 72 | // runtime state ///////////////////////////// |
||
| 73 | protected $activityId; |
||
| 74 | protected $jobDefinition; |
||
| 75 | protected $execution; |
||
| 76 | |||
| 77 | // sequence counter ////////////////////////// |
||
| 78 | protected $sequenceCounter = 1; |
||
| 79 | |||
| 80 | // last failure log id /////////////////////// |
||
| 81 | protected $lastFailureLogId; |
||
| 82 | |||
| 83 | // last failing activity id /////////////////////// |
||
| 84 | protected $failedActivityId; |
||
| 85 | |||
| 86 | protected $persistedDependentEntities; |
||
| 87 | |||
| 88 | public function execute(CommandContext $commandContext) |
||
| 89 | { |
||
| 90 | $execution = null; |
||
| 91 | if ($this->executionId !== null) { |
||
| 92 | $execution = $this->getExecution(); |
||
| 93 | EnsureUtil::ensureNotNull("Cannot find execution with id '" . $this->executionId . "' referenced from job '" . $this . "'", "execution", $execution); |
||
| 94 | } |
||
| 95 | |||
| 96 | // initialize activity id |
||
| 97 | $this->getActivityId(); |
||
| 98 | |||
| 99 | // increment sequence counter before job execution |
||
| 100 | $this->incrementSequenceCounter(); |
||
| 101 | |||
| 102 | $this->preExecute($commandContext); |
||
| 103 | $jobHandler = $this->getJobHandler(); |
||
| 104 | $configuration = $this->getJobHandlerConfiguration(); |
||
| 105 | EnsureUtil::ensureNotNull("Cannot find job handler '" . $this->jobHandlerType . "' from job '" . $this . "'", "jobHandler", $jobHandler); |
||
| 106 | $jobHandler->execute($configuration, $execution, $commandContext, $this->tenantId); |
||
| 107 | $this->postExecute($commandContext); |
||
| 108 | } |
||
| 109 | |||
| 110 | protected function preExecute(CommandContext $commandContext): void |
||
| 111 | { |
||
| 112 | // nothing to do |
||
| 113 | } |
||
| 114 | |||
| 115 | protected function postExecute(CommandContext $commandContext): void |
||
| 116 | { |
||
| 117 | //LOG.debugJobExecuted(this); |
||
| 118 | $this->delete(true); |
||
| 119 | $commandContext->getHistoricJobLogManager()->fireJobSuccessfulEvent($this); |
||
| 120 | } |
||
| 121 | |||
| 122 | public function init(CommandContext $commandContext): void |
||
| 123 | { |
||
| 124 | // nothing to do |
||
| 125 | } |
||
| 126 | |||
| 127 | public function insert(): void |
||
| 128 | { |
||
| 129 | $commandContext = Context::getCommandContext(); |
||
| 130 | |||
| 131 | // add link to execution and deployment |
||
| 132 | $execution = $this->getExecution(); |
||
| 133 | if ($execution !== null) { |
||
| 134 | $execution->addJob($this); |
||
| 135 | |||
| 136 | $processDefinition = $execution->getProcessDefinition(); |
||
| 137 | $this->deploymentId = $processDefinition->getDeploymentId(); |
||
| 138 | } |
||
| 139 | |||
| 140 | $commandContext |
||
| 141 | ->getJobManager() |
||
| 142 | ->insertJob($this); |
||
| 143 | } |
||
| 144 | |||
| 145 | public function delete(?bool $incidentResolved = false): void |
||
| 146 | { |
||
| 147 | $commandContext = Context::getCommandContext(); |
||
| 148 | |||
| 149 | $this->incrementSequenceCounter(); |
||
| 150 | |||
| 151 | // clean additional data related to this job |
||
| 152 | $jobHandler = $this->getJobHandler(); |
||
| 153 | if ($jobHandler !== null) { |
||
| 154 | $jobHandler->onDelete($this->getJobHandlerConfiguration(), $this); |
||
| 155 | } |
||
| 156 | |||
| 157 | // fire delete event if this job is not being executed |
||
| 158 | $executingJob = $this->equals($commandContext->getCurrentJob()); |
||
| 159 | $commandContext->getJobManager()->deleteJob($this, !$executingJob); |
||
| 160 | |||
| 161 | // Also delete the job's exception byte array |
||
| 162 | if ($this->exceptionByteArrayId !== null) { |
||
| 163 | $commandContext->getByteArrayManager()->deleteByteArrayById($this->exceptionByteArrayId); |
||
| 164 | } |
||
| 165 | |||
| 166 | // remove link to execution |
||
| 167 | $execution = $this->getExecution(); |
||
| 168 | if ($execution !== null) { |
||
| 169 | $execution->removeJob($this); |
||
| 170 | } |
||
| 171 | |||
| 172 | $this->removeFailedJobIncident($incidentResolved); |
||
| 173 | } |
||
| 174 | |||
| 175 | public function getPersistentState() |
||
| 176 | { |
||
| 177 | $persistentState = parent::getPersistentState(); |
||
| 178 | $persistentState["executionId"] = $this->executionId; |
||
| 179 | $persistentState["retries"] = $this->retries; |
||
| 180 | $persistentState["exceptionMessage"] = $this->exceptionMessage; |
||
| 181 | $persistentState["suspensionState"] = $this->suspensionState; |
||
| 182 | $persistentState["processDefinitionId"] = $this->processDefinitionId; |
||
| 183 | $persistentState["jobDefinitionId"] = $this->jobDefinitionId; |
||
| 184 | $persistentState["deploymentId"] = $this->deploymentId; |
||
| 185 | $persistentState["jobHandlerConfiguration"] = $this->jobHandlerConfiguration; |
||
| 186 | $persistentState["priority"] = $this->priority; |
||
| 187 | $persistentState["tenantId"] = $this->tenantId; |
||
| 188 | if ($this->exceptionByteArrayId !== null) { |
||
| 189 | $persistentState["exceptionByteArrayId"] = $this->exceptionByteArrayId; |
||
| 190 | } |
||
| 191 | return $persistentState; |
||
| 192 | } |
||
| 193 | |||
| 194 | public function setExecution(ExecutionEntity $execution): void |
||
| 195 | { |
||
| 196 | if ($execution !== null) { |
||
| 197 | $this->execution = $execution; |
||
| 198 | $this->executionId = $execution->getId(); |
||
| 199 | $this->processInstanceId = $execution->getProcessInstanceId(); |
||
| 200 | $this->execution->addJob($this); |
||
| 201 | } else { |
||
| 202 | $this->execution->removeJob($this); |
||
| 203 | $this->execution = $execution; |
||
| 204 | $this->processInstanceId = null; |
||
| 205 | $this->executionId = null; |
||
| 206 | } |
||
| 207 | } |
||
| 208 | |||
| 209 | // sequence counter ///////////////////////////////////////////////////////// |
||
| 210 | |||
| 211 | public function getSequenceCounter(): int |
||
| 212 | { |
||
| 213 | return $this->sequenceCounter; |
||
| 214 | } |
||
| 215 | |||
| 216 | public function setSequenceCounter(int $sequenceCounter): void |
||
| 217 | { |
||
| 218 | $this->sequenceCounter = $sequenceCounter; |
||
| 219 | } |
||
| 220 | |||
| 221 | public function incrementSequenceCounter(): void |
||
| 222 | { |
||
| 223 | $this->sequenceCounter += 1; |
||
| 224 | } |
||
| 225 | |||
| 226 | // getters and setters ////////////////////////////////////////////////////// |
||
| 227 | |||
| 228 | public function getExecutionId(): string |
||
| 229 | { |
||
| 230 | return $this->executionId; |
||
| 231 | } |
||
| 232 | |||
| 233 | public function setExecutionId(string $executionId): void |
||
| 234 | { |
||
| 235 | $this->executionId = $executionId; |
||
| 236 | } |
||
| 237 | |||
| 238 | public function getExecution(): ?ExecutionEntity |
||
| 239 | { |
||
| 240 | $this->ensureExecutionInitialized(); |
||
| 241 | return $this->execution; |
||
| 242 | } |
||
| 243 | |||
| 244 | protected function ensureExecutionInitialized(): void |
||
| 245 | { |
||
| 246 | if ($this->execution === null && $this->executionId !== null) { |
||
| 247 | $this->execution = Context::getCommandContext() |
||
| 248 | ->getExecutionManager() |
||
| 249 | ->findExecutionById($this->executionId); |
||
| 250 | } |
||
| 251 | } |
||
| 252 | |||
| 253 | public function getRetries(): int |
||
| 254 | { |
||
| 255 | return $this->retries; |
||
| 256 | } |
||
| 257 | |||
| 258 | public function setRetries(int $retries): void |
||
| 259 | { |
||
| 260 | // if retries should be set to a negative value set it to 0 |
||
| 261 | if ($retries < 0) { |
||
| 262 | $retries = 0; |
||
| 263 | } |
||
| 264 | |||
| 265 | // Assuming: if the number of retries will |
||
| 266 | // be changed from 0 to x (x >= 1), means |
||
| 267 | // that the corresponding incident is resolved. |
||
| 268 | if ($this->retries == 0 && $retries > 0) { |
||
| 269 | $this->removeFailedJobIncident(true); |
||
| 270 | } |
||
| 271 | |||
| 272 | // If the retries will be set to 0, an |
||
| 273 | // incident has to be created. |
||
| 274 | if ($retries == 0 && $this->retries > 0) { |
||
| 275 | $this->createFailedJobIncident(); |
||
| 276 | } |
||
| 277 | $this->retries = $retries; |
||
| 278 | } |
||
| 279 | |||
| 280 | // special setter for MyBatis which does not influence incidents |
||
| 281 | public function setRetriesFromPersistence(int $retries): void |
||
| 282 | { |
||
| 283 | $this->retries = $retries; |
||
| 284 | } |
||
| 285 | |||
| 286 | protected function createFailedJobIncident(): void |
||
| 287 | { |
||
| 288 | $processEngineConfiguration = Context::getProcessEngineConfiguration(); |
||
| 289 | |||
| 290 | if ($processEngineConfiguration->isCreateIncidentOnFailedJobEnabled()) { |
||
| 291 | $incidentHandlerType = IncidentInterface::FAILED_JOB_HANDLER_TYPE; |
||
| 292 | |||
| 293 | // make sure job has an ID set: |
||
| 294 | if ($this->id === null) { |
||
| 295 | $this->id = $processEngineConfiguration |
||
| 296 | ->getIdGenerator() |
||
| 297 | ->getNextId(); |
||
| 298 | } else { |
||
| 299 | // check whether there exists already an incident |
||
| 300 | // for this job |
||
| 301 | $failedJobIncidents = Context::getCommandContext() |
||
| 302 | ->getIncidentManager() |
||
| 303 | ->findIncidentByConfigurationAndIncidentType($this->id, $incidentHandlerType); |
||
| 304 | |||
| 305 | if (!empty($failedJobIncidents)) { |
||
| 306 | // update the historic job log id in the historic incidents (if available) |
||
| 307 | foreach ($failedJobIncidents as $incident) { |
||
| 308 | $historicIncidentEvent = Context::getCommandContext() |
||
| 309 | ->getHistoricIncidentManager() |
||
| 310 | ->findHistoricIncidentById($incident->getId()); |
||
| 311 | if ($historicIncidentEvent !== null) { |
||
| 312 | $historicIncidentEvent->setHistoryConfiguration($this->getLastFailureLogId()); |
||
| 313 | Context::getCommandContext()->getDbEntityManager()->merge($historicIncidentEvent); |
||
| 314 | } |
||
| 315 | } |
||
| 316 | return; |
||
| 317 | } |
||
| 318 | } |
||
| 319 | $incidentContext = $this->createIncidentContext(); |
||
| 320 | $incidentContext->setActivityId($this->getActivityId()); |
||
| 321 | $incidentContext->setHistoryConfiguration($this->getLastFailureLogId()); |
||
| 322 | $incidentContext->setFailedActivityId($this->getFailedActivityId()); |
||
| 323 | IncidentHandling::createIncident($incidentHandlerType, $incidentContext, $this->exceptionMessage); |
||
| 324 | } |
||
| 325 | } |
||
| 326 | |||
| 327 | protected function removeFailedJobIncident(bool $incidentResolved): void |
||
| 328 | { |
||
| 329 | $incidentContext = $this->createIncidentContext(); |
||
| 330 | IncidentHandling::removeIncidents(IncidentInterface::FAILED_JOB_HANDLER_TYPE, $incidentContext, $incidentResolved); |
||
| 331 | } |
||
| 332 | |||
| 333 | protected function createIncidentContext(): IncidentContext |
||
| 334 | { |
||
| 335 | $incidentContext = new IncidentContext(); |
||
| 336 | $incidentContext->setProcessDefinitionId($this->processDefinitionId); |
||
| 337 | $incidentContext->setExecutionId($this->executionId); |
||
| 338 | $incidentContext->setTenantId($this->tenantId); |
||
| 339 | $incidentContext->setConfiguration($this->id); |
||
| 340 | $incidentContext->setJobDefinitionId($this->jobDefinitionId); |
||
| 341 | |||
| 342 | return $incidentContext; |
||
| 343 | } |
||
| 344 | |||
| 345 | public function getExceptionStacktrace(): string |
||
| 346 | { |
||
| 347 | $byteArray = $this->getExceptionByteArray(); |
||
| 348 | return ExceptionUtil::getExceptionStacktrace($byteArray); |
||
| 349 | } |
||
| 350 | |||
| 351 | public function setSuspensionState(int $state): void |
||
| 352 | { |
||
| 353 | $this->suspensionState = $state; |
||
| 354 | } |
||
| 355 | |||
| 356 | public function getSuspensionState(): int |
||
| 357 | { |
||
| 358 | return $this->suspensionState; |
||
| 359 | } |
||
| 360 | |||
| 361 | public function isSuspended(): bool |
||
| 362 | { |
||
| 363 | return $this->suspensionState == SuspensionState::suspended()->getStateCode(); |
||
| 364 | } |
||
| 365 | |||
| 366 | public function getProcessDefinitionId(): string |
||
| 367 | { |
||
| 368 | return $this->processDefinitionId; |
||
| 369 | } |
||
| 370 | |||
| 371 | public function setProcessDefinitionId(string $processDefinitionId): void |
||
| 372 | { |
||
| 373 | $this->processDefinitionId = $processDefinitionId; |
||
| 374 | } |
||
| 375 | |||
| 376 | public function getProcessDefinitionKey(): string |
||
| 377 | { |
||
| 378 | return $this->processDefinitionKey; |
||
| 379 | } |
||
| 380 | |||
| 381 | public function setProcessDefinitionKey(string $processDefinitionKey): void |
||
| 382 | { |
||
| 383 | $this->processDefinitionKey = $processDefinitionKey; |
||
| 384 | } |
||
| 385 | |||
| 386 | public function setExceptionStacktrace(string $exception): void |
||
| 387 | { |
||
| 388 | $exceptionBytes = $exception; |
||
| 389 | |||
| 390 | $byteArray = $this->getExceptionByteArray(); |
||
| 391 | |||
| 392 | if ($byteArray === null) { |
||
| 393 | $byteArray = ExceptionUtil::createJobExceptionByteArray($exceptionBytes, ResourceTypes::runtime()); |
||
| 394 | $this->exceptionByteArrayId = $byteArray->getId(); |
||
| 395 | $this->exceptionByteArray = $byteArray; |
||
| 396 | } else { |
||
| 397 | $byteArray->setBytes($exceptionBytes); |
||
| 398 | } |
||
| 399 | } |
||
| 400 | |||
| 401 | protected function getJobHandler(): ?JobHandlerInterface |
||
| 402 | { |
||
| 403 | $jobHandlers = Context::getProcessEngineConfiguration()->getJobHandlers(); |
||
| 404 | if (array_key_exists($this->jobHandlerType, $jobHandlers)) { |
||
| 405 | return $jobHandlers[$this->jobHandlerType]; |
||
| 406 | } |
||
| 407 | return null; |
||
| 408 | } |
||
| 409 | |||
| 410 | public function getJobHandlerConfiguration(): ?JobHandlerConfigurationInterface |
||
| 411 | { |
||
| 412 | $handler = $this->getJobHandler(); |
||
| 413 | if ($handler !== null) { |
||
| 414 | return $handler->newConfiguration($this->jobHandlerConfiguration); |
||
| 415 | } |
||
| 416 | return null; |
||
| 417 | } |
||
| 418 | |||
| 419 | public function setJobHandlerConfiguration(JobHandlerConfigurationInterface $configuration): void |
||
| 420 | { |
||
| 421 | $this->jobHandlerConfiguration = $configuration->toCanonicalString(); |
||
| 422 | } |
||
| 423 | |||
| 424 | public function getJobHandlerType(): string |
||
| 425 | { |
||
| 426 | return $this->jobHandlerType; |
||
| 427 | } |
||
| 428 | |||
| 429 | public function setJobHandlerType(string $jobHandlerType): void |
||
| 430 | { |
||
| 431 | $this->jobHandlerType = $jobHandlerType; |
||
| 432 | } |
||
| 433 | |||
| 434 | public function getJobHandlerConfigurationRaw(): string |
||
| 435 | { |
||
| 436 | return $this->jobHandlerConfiguration; |
||
| 437 | } |
||
| 438 | |||
| 439 | public function setJobHandlerConfigurationRaw(string $jobHandlerConfiguration): void |
||
| 440 | { |
||
| 441 | $this->jobHandlerConfiguration = $jobHandlerConfiguration; |
||
| 442 | } |
||
| 443 | |||
| 444 | public function getExceptionMessage(): ?string |
||
| 447 | } |
||
| 448 | |||
| 449 | public function getJobDefinitionId(): ?string |
||
| 450 | { |
||
| 451 | return $this->jobDefinitionId; |
||
| 452 | } |
||
| 453 | |||
| 454 | public function setJobDefinitionId(string $jobDefinitionId): void |
||
| 455 | { |
||
| 456 | $this->jobDefinitionId = $jobDefinitionId; |
||
| 457 | } |
||
| 458 | |||
| 459 | public function getJobDefinition(): ?JobDefinitionInterface |
||
| 460 | { |
||
| 461 | $this->ensureJobDefinitionInitialized(); |
||
| 462 | return $this->jobDefinition; |
||
| 463 | } |
||
| 464 | |||
| 465 | public function setJobDefinition(?JobDefinitionInterface $jobDefinition): void |
||
| 466 | { |
||
| 467 | $this->jobDefinition = $jobDefinition; |
||
| 468 | if ($jobDefinition !== null) { |
||
| 469 | $this->jobDefinitionId = $jobDefinition->getId(); |
||
| 470 | } else { |
||
| 471 | $this->jobDefinitionId = null; |
||
| 472 | } |
||
| 473 | } |
||
| 474 | |||
| 475 | protected function ensureJobDefinitionInitialized(): void |
||
| 476 | { |
||
| 477 | if ($this->jobDefinition === null && $this->jobDefinitionId !== null) { |
||
| 478 | $this->jobDefinition = Context::getCommandContext() |
||
| 479 | ->getJobDefinitionManager() |
||
| 480 | ->findById($this->jobDefinitionId); |
||
| 481 | } |
||
| 482 | } |
||
| 483 | |||
| 484 | public function setExceptionMessage(string $exceptionMessage): void |
||
| 485 | { |
||
| 486 | $this->exceptionMessage = StringUtil::trimToMaximumLengthAllowed($exceptionMessage); |
||
| 487 | } |
||
| 488 | |||
| 489 | public function getExceptionByteArrayId(): ?string |
||
| 490 | { |
||
| 491 | return $this->exceptionByteArrayId; |
||
| 492 | } |
||
| 493 | |||
| 494 | protected function getExceptionByteArray(): ?ByteArrayEntity |
||
| 495 | { |
||
| 496 | $this->ensureExceptionByteArrayInitialized(); |
||
| 497 | return $this->exceptionByteArray; |
||
| 498 | } |
||
| 499 | |||
| 500 | protected function ensureExceptionByteArrayInitialized(): void |
||
| 501 | { |
||
| 502 | if ($this->exceptionByteArray === null && $this->exceptionByteArrayId !== null) { |
||
| 503 | $this->exceptionByteArray = Context::getCommandContext() |
||
| 504 | ->getDbEntityManager() |
||
| 505 | ->selectById(ByteArrayEntity::class, $this->exceptionByteArrayId); |
||
| 506 | } |
||
| 507 | } |
||
| 508 | |||
| 509 | protected function clearFailedJobException(): void |
||
| 510 | { |
||
| 511 | $byteArray = $this->getExceptionByteArray(); |
||
| 512 | |||
| 513 | // Avoid NPE when the job was reconfigured by another |
||
| 514 | // node in the meantime |
||
| 515 | if ($byteArray !== null) { |
||
| 516 | Context::getCommandContext() |
||
| 517 | ->getDbEntityManager() |
||
| 518 | ->delete($byteArray); |
||
| 519 | } |
||
| 520 | |||
| 521 | $this->exceptionByteArrayId = null; |
||
| 522 | $this->exceptionMessage = null; |
||
| 523 | } |
||
| 524 | |||
| 525 | public function getDeploymentId(): ?string |
||
| 526 | { |
||
| 527 | return $this->deploymentId; |
||
| 528 | } |
||
| 529 | |||
| 530 | public function setDeploymentId(string $deploymentId): void |
||
| 531 | { |
||
| 532 | $this->deploymentId = $this->deploymentId; |
||
| 533 | } |
||
| 534 | |||
| 535 | public function isInInconsistentLockState(): bool |
||
| 536 | { |
||
| 537 | return ($this->lockOwner !== null && $this->lockExpirationTime === null) |
||
| 538 | || ($this->retries == 0 && ($this->lockOwner !== null || $this->lockExpirationTime !== null)); |
||
| 539 | } |
||
| 540 | |||
| 541 | public function resetLock(): void |
||
| 542 | { |
||
| 543 | $this->lockOwner = null; |
||
| 544 | $this->lockExpirationTime = null; |
||
| 545 | } |
||
| 546 | |||
| 547 | public function getActivityId(): string |
||
| 548 | { |
||
| 549 | $this->ensureActivityIdInitialized(); |
||
| 550 | return $this->activityId; |
||
| 551 | } |
||
| 552 | |||
| 553 | public function setActivityId(string $activityId): void |
||
| 554 | { |
||
| 555 | $this->activityId = $activityId; |
||
| 556 | } |
||
| 557 | |||
| 558 | public function getPriority(): int |
||
| 561 | } |
||
| 562 | |||
| 563 | public function setPriority(int $priority): void |
||
| 564 | { |
||
| 565 | $this->priority = $priority; |
||
| 566 | } |
||
| 567 | |||
| 568 | public function getTenantId(): ?string |
||
| 569 | { |
||
| 570 | return $this->tenantId; |
||
| 571 | } |
||
| 572 | |||
| 573 | public function setTenantId(?string $tenantId): void |
||
| 574 | { |
||
| 575 | $this->tenantId = $tenantId; |
||
| 576 | } |
||
| 577 | |||
| 578 | public function getCreateTime(): string |
||
| 579 | { |
||
| 580 | return $this->createTime; |
||
| 581 | } |
||
| 582 | |||
| 583 | public function setCreateTime(string $createTime): void |
||
| 584 | { |
||
| 585 | $this->createTime = $createTime; |
||
| 586 | } |
||
| 587 | |||
| 588 | protected function ensureActivityIdInitialized(): void |
||
| 589 | { |
||
| 590 | if ($this->activityId === null) { |
||
| 591 | $jobDefinition = $this->getJobDefinition(); |
||
| 592 | if ($jobDefinition !== null) { |
||
| 593 | $this->activityId = $jobDefinition->getActivityId(); |
||
| 594 | } else { |
||
| 595 | $execution = $this->getExecution(); |
||
| 596 | if ($execution !== null) { |
||
| 597 | $this->activityId = $execution->getActivityId(); |
||
| 598 | } |
||
| 599 | } |
||
| 600 | } |
||
| 601 | } |
||
| 602 | |||
| 603 | /** |
||
| 604 | * |
||
| 605 | * Unlock from current lock owner |
||
| 606 | * |
||
| 607 | */ |
||
| 608 | public function unlock(): void |
||
| 609 | { |
||
| 610 | $this->lockOwner = null; |
||
| 611 | $this->lockExpirationTime = null; |
||
| 612 | } |
||
| 613 | |||
| 614 | abstract public function getType(): string; |
||
| 615 | |||
| 616 | public function equals($obj): bool |
||
| 617 | { |
||
| 618 | if ($this == $obj) { |
||
| 619 | return true; |
||
| 620 | } |
||
| 621 | if ($obj === null) { |
||
| 622 | return false; |
||
| 623 | } |
||
| 624 | if (get_class($this) != get_class($obj)) { |
||
| 625 | return false; |
||
| 626 | } |
||
| 627 | if ($this->id === null) { |
||
| 628 | if ($obj->id !== null) { |
||
| 629 | return false; |
||
| 630 | } |
||
| 631 | } elseif ($this->id != $obj->id) { |
||
| 632 | return false; |
||
| 633 | } |
||
| 634 | return true; |
||
| 635 | } |
||
| 636 | |||
| 637 | public function getReferencedEntityIds(): array |
||
| 640 | } |
||
| 641 | |||
| 642 | public function getReferencedEntitiesIdAndClass(): array |
||
| 643 | { |
||
| 644 | $referenceIdAndClass = []; |
||
| 645 | |||
| 646 | if ($this->exceptionByteArrayId !== null) { |
||
| 647 | $referenceIdAndClass[$this->exceptionByteArrayId] = ByteArrayEntity::class; |
||
| 648 | } |
||
| 649 | |||
| 650 | return $referenceIdAndClass; |
||
| 651 | } |
||
| 652 | |||
| 653 | public function getDependentEntities(): array |
||
| 654 | { |
||
| 655 | return $this->persistedDependentEntities; |
||
| 656 | } |
||
| 657 | |||
| 658 | public function postLoad(): void |
||
| 659 | { |
||
| 660 | if ($this->exceptionByteArrayId !== null) { |
||
| 661 | $this->persistedDependentEntities = []; |
||
| 662 | $this->persistedDependentEntities[$this->exceptionByteArrayId] = ByteArrayEntity::class; |
||
| 663 | } else { |
||
| 664 | $this->persistedDependentEntities = []; |
||
| 665 | } |
||
| 666 | } |
||
| 667 | |||
| 668 | public function getLastFailureLogId(): ?string |
||
| 669 | { |
||
| 670 | return $this->lastFailureLogId; |
||
| 671 | } |
||
| 672 | |||
| 673 | public function setLastFailureLogId(string $lastFailureLogId): void |
||
| 676 | } |
||
| 677 | |||
| 678 | public function getFailedActivityId(): ?string |
||
| 679 | { |
||
| 680 | return $this->failedActivityId; |
||
| 681 | } |
||
| 682 | |||
| 683 | public function setFailedActivityId(string $failedActivityId): void |
||
| 684 | { |
||
| 685 | $this->failedActivityId = $failedActivityId; |
||
| 686 | } |
||
| 687 | |||
| 688 | public function serialize() |
||
| 689 | { |
||
| 690 | return json_encode([ |
||
| 691 | 'id' => $this->id, |
||
| 692 | 'revision' => $this->revision, |
||
| 693 | 'duedate' => $this->duedate, |
||
| 694 | 'lockOwner' => $this->lockOwner, |
||
| 695 | 'lockExpirationTime' => $this->lockExpirationTime, |
||
| 696 | 'executionId' => $this->executionId, |
||
| 697 | 'processInstanceId' => $this->processInstanceId, |
||
| 698 | 'isExclusive' => $this->isExclusive, |
||
| 699 | 'jobDefinitionId' => $this->jobDefinitionId, |
||
| 700 | 'jobHandlerType' => $this->jobHandlerType, |
||
| 701 | 'jobHandlerConfiguration' => $this->jobHandlerConfiguration, |
||
| 702 | 'exceptionByteArray' => serialize($this->exceptionByteArray), |
||
| 703 | 'exceptionByteArrayId' => $this->exceptionByteArrayId, |
||
| 704 | 'exceptionMessage' => $this->exceptionMessage, |
||
| 705 | 'failedActivityId' => $this->failedActivityId, |
||
| 706 | 'deploymentId' => $this->deploymentId, |
||
| 707 | 'priority' => $this->priority, |
||
| 708 | 'tenantId' => $this->tenantId |
||
| 709 | ]); |
||
| 710 | } |
||
| 711 | |||
| 712 | public function unserialize($data) |
||
| 713 | { |
||
| 714 | $json = json_decode($data); |
||
| 715 | $this->id = $json->id; |
||
| 716 | $this->revision = $json->revision; |
||
| 717 | $this->lockOwner = $json->lockOwner; |
||
| 718 | $this->lockExpirationTime = $json->lockExpirationTime; |
||
| 719 | $this->executionId = $json->executionId; |
||
| 720 | $this->processInstanceId = $json->processInstanceId; |
||
| 721 | $this->isExclusive = $json->isExclusive; |
||
| 722 | $this->jobDefinitionId = $json->jobDefinitionId; |
||
| 723 | $this->jobHandlerType = $json->jobHandlerType; |
||
| 724 | $this->jobHandlerConfiguration = $json->jobHandlerConfiguration; |
||
| 725 | $this->exceptionByteArray = unserialize($json->exceptionByteArray); |
||
| 726 | $this->exceptionByteArrayId = $json->exceptionByteArrayId; |
||
| 727 | $this->exceptionMessage = $json->exceptionMessage; |
||
| 728 | $this->failedActivityId = $json->failedActivityId; |
||
| 729 | $this->deploymentId = $json->deploymentId; |
||
| 730 | $this->priority = $json->priority; |
||
| 731 | $this->tenantId = $json->tenantId; |
||
| 732 | } |
||
| 733 | |||
| 734 | public function __toString() |
||
| 757 | } |
||
| 758 | } |
||
| 759 |