|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Jabe\Engine\Impl; |
|
4
|
|
|
|
|
5
|
|
|
use Jabe\Engine\ProcessEngineException; |
|
6
|
|
|
use Jabe\Engine\Impl\Context\{ |
|
7
|
|
|
Context, |
|
8
|
|
|
ProcessApplicationContextUtil |
|
9
|
|
|
}; |
|
10
|
|
|
use Jabe\Engine\Impl\Core\Variable\Mapping\Value\ParameterValueProviderInterface; |
|
11
|
|
|
use Jabe\Engine\Impl\Persistence\Entity\ExecutionEntity; |
|
12
|
|
|
use Jabe\Engine\Impl\Pvm\Process\ProcessDefinitionImpl; |
|
13
|
|
|
|
|
14
|
|
|
abstract class DefaultPriorityProvider implements PriorityProviderInterface |
|
|
|
|
|
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* The default priority. |
|
18
|
|
|
*/ |
|
19
|
|
|
public const DEFAULT_PRIORITY = 0; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* The default priority in case of resolution failure. |
|
23
|
|
|
*/ |
|
24
|
|
|
public const DEFAULT_PRIORITY_ON_RESOLUTION_FAILURE = 0; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Returns the default priority. |
|
28
|
|
|
* |
|
29
|
|
|
* @return the default priority |
|
|
|
|
|
|
30
|
|
|
*/ |
|
31
|
|
|
public function getDefaultPriority(): int |
|
32
|
|
|
{ |
|
33
|
|
|
return self::DEFAULT_PRIORITY; |
|
|
|
|
|
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Returns the default priority in case of resolution failure. |
|
38
|
|
|
* |
|
39
|
|
|
* @return the default priority |
|
40
|
|
|
*/ |
|
41
|
|
|
public function getDefaultPriorityOnResolutionFailure(): int |
|
42
|
|
|
{ |
|
43
|
|
|
return self::DEFAULT_PRIORITY_ON_RESOLUTION_FAILURE; |
|
|
|
|
|
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Evaluates a given value provider with the given execution entity to determine |
|
48
|
|
|
* the correct value. The error message heading is used for the error message |
|
49
|
|
|
* if the validation fails because the value is no valid priority. |
|
50
|
|
|
* |
|
51
|
|
|
* @param valueProvider the provider which contains the value |
|
52
|
|
|
* @param execution the execution entity |
|
53
|
|
|
* @param errorMessageHeading the heading which is used for the error message |
|
54
|
|
|
* @return the valid priority value |
|
55
|
|
|
*/ |
|
56
|
|
|
protected function evaluateValueProvider(ParameterValueProviderInterface $valueProvider, ExecutionEntity $execution, string $errorMessageHeading): int |
|
57
|
|
|
{ |
|
58
|
|
|
$value = null; |
|
|
|
|
|
|
59
|
|
|
try { |
|
60
|
|
|
$value = $valueProvider->getValue($execution); |
|
61
|
|
|
} catch (ProcessEngineException $e) { |
|
62
|
|
|
if ( |
|
63
|
|
|
Context::getProcessEngineConfiguration()->isEnableGracefulDegradationOnContextSwitchFailure() |
|
|
|
|
|
|
64
|
|
|
&& $this->isSymptomOfContextSwitchFailure($e, $execution) |
|
65
|
|
|
) { |
|
66
|
|
|
$value = $this->getDefaultPriorityOnResolutionFailure(); |
|
67
|
|
|
$this->logNotDeterminingPriority($execution, $value, $e); |
|
|
|
|
|
|
68
|
|
|
} else { |
|
69
|
|
|
throw e; |
|
|
|
|
|
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
if (!is_int($value)) { |
|
74
|
|
|
throw new ProcessEngineException($errorMessageHeading . ": Priority value is not an Integer"); |
|
75
|
|
|
} else { |
|
76
|
|
|
$numberValue = $value; |
|
77
|
|
|
if ($this->isValidLongValue($numberValue)) { |
|
|
|
|
|
|
78
|
|
|
return $numberValue; |
|
|
|
|
|
|
79
|
|
|
} else { |
|
80
|
|
|
throw new ProcessEngineException($errorMessageHeading . ": Priority value must be either Short, Integer, or Long"); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function determinePriority(ExecutionEntity $execution, $param, string $jobDefinitionId): int |
|
86
|
|
|
{ |
|
87
|
|
|
if ($param != null || $execution != null) { |
|
88
|
|
|
$specificPriority = $this->getSpecificPriority($execution, $param, $jobDefinitionId); |
|
89
|
|
|
if ($specificPriority != null) { |
|
90
|
|
|
return $specificPriority; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
$processDefinitionPriority = $this->getProcessDefinitionPriority($execution, $param); |
|
94
|
|
|
if ($processDefinitionPriority != null) { |
|
95
|
|
|
return $processDefinitionPriority; |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
return $this->getDefaultPriority(); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Returns the priority defined in the specific entity. Like a job definition priority or |
|
103
|
|
|
* an activity priority. The result can also be null in that case the process |
|
104
|
|
|
* priority will be used. |
|
105
|
|
|
* |
|
106
|
|
|
* @param execution the current execution |
|
107
|
|
|
* @param param the generic param |
|
108
|
|
|
* @param jobDefinitionId the job definition id if related to a job |
|
109
|
|
|
* @return the specific priority |
|
110
|
|
|
*/ |
|
111
|
|
|
abstract protected function getSpecificPriority(ExecutionEntity $execution, $param, string $jobDefinitionId): int; |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Returns the priority defined in the process definition. Can also be null |
|
115
|
|
|
* in that case the fallback is the default priority. |
|
116
|
|
|
* |
|
117
|
|
|
* @param execution the current execution |
|
118
|
|
|
* @param param the generic param |
|
119
|
|
|
* @return the priority defined in the process definition |
|
120
|
|
|
*/ |
|
121
|
|
|
abstract protected function getProcessDefinitionPriority(ExecutionEntity $execution, $param): int; |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* Returns the priority which is defined in the given process definition. |
|
125
|
|
|
* The priority value is identified with the given propertyKey. |
|
126
|
|
|
* Returns null if the process definition is null or no priority was defined. |
|
127
|
|
|
* |
|
128
|
|
|
* @param processDefinition the process definition that should contains the priority |
|
129
|
|
|
* @param propertyKey the key which identifies the property |
|
130
|
|
|
* @param execution the current execution |
|
131
|
|
|
* @param errorMsgHead the error message header which is used if the evaluation fails |
|
132
|
|
|
* @return the priority defined in the given process |
|
133
|
|
|
*/ |
|
134
|
|
|
protected function getProcessDefinedPriority(ProcessDefinitionImpl $processDefinition, string $propertyKey, ExecutionEntity $execution, string $errorMsgHead): ?int |
|
135
|
|
|
{ |
|
136
|
|
|
if ($processDefinition != null) { |
|
137
|
|
|
$priorityProvider = $processDefinition->getProperty($propertyKey); |
|
138
|
|
|
if ($priorityProvider != null) { |
|
139
|
|
|
return $this->evaluateValueProvider($priorityProvider, $execution, $errorMsgHead); |
|
|
|
|
|
|
140
|
|
|
} |
|
141
|
|
|
} |
|
142
|
|
|
return null; |
|
143
|
|
|
} |
|
144
|
|
|
/** |
|
145
|
|
|
* Logs the exception which was thrown if the priority can not be determined. |
|
146
|
|
|
* |
|
147
|
|
|
* @param execution the current execution entity |
|
148
|
|
|
* @param value the current value |
|
149
|
|
|
* @param e the exception which was catched |
|
150
|
|
|
*/ |
|
151
|
|
|
abstract protected function logNotDeterminingPriority(ExecutionEntity $execution, $value, ProcessEngineException $e): void; |
|
152
|
|
|
|
|
153
|
|
|
protected function isSymptomOfContextSwitchFailure(\Throwable $t, ExecutionEntity $contextExecution): bool |
|
154
|
|
|
{ |
|
155
|
|
|
// a context switch failure can occur, if the current engine has no PA registration for the deployment |
|
156
|
|
|
// subclasses may assert the actual throwable to narrow down the diagnose |
|
157
|
|
|
return ProcessApplicationContextUtil::getTargetProcessApplication($contextExecution) == null; |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* Checks if the given number is a valid long value. |
|
162
|
|
|
* @param value the number which should be checked |
|
163
|
|
|
* @return true if is a valid long value, false otherwise |
|
164
|
|
|
*/ |
|
165
|
|
|
protected function isValidLongValue($value): bool |
|
166
|
|
|
{ |
|
167
|
|
|
return is_int($value); |
|
|
|
|
|
|
168
|
|
|
} |
|
169
|
|
|
} |
|
170
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths