-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJobConfigurationProvider.php
More file actions
74 lines (63 loc) · 1.92 KB
/
Copy pathJobConfigurationProvider.php
File metadata and controls
74 lines (63 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
namespace Oro\Bundle\MessageQueueBundle\Provider;
use Oro\Component\MessageQueue\Provider\JobConfigurationProviderInterface;
/**
* Provides information about number of seconds, after which job should be considered as stale.
*/
class JobConfigurationProvider implements JobConfigurationProviderInterface
{
const JOBS_ARRAY_KEY = 'jobs';
const JOB_NAME_DEFAULT_KEY = 'default';
const JOB_NAME_DELIMITERS = ['dot' => '.', 'colon' => ':'];
/**
* @var array
*/
private $configuration = [];
/**
* {@inheritdoc}
*/
public function getTimeBeforeStaleForJobName($jobName)
{
return $this->checkKeyByJobNameOrItsPart($jobName)
?? $this->configuration[self::JOB_NAME_DEFAULT_KEY]
?? null;
}
public function setConfiguration(array $jobConfiguration)
{
$this->configuration = $jobConfiguration;
}
/**
* @param $jobName
*
* @return null|int
*/
private function checkKeyByJobNameOrItsPart($jobName)
{
if (isset($this->configuration[self::JOBS_ARRAY_KEY][$jobName])
&& $this->configuration[self::JOBS_ARRAY_KEY][$jobName]
) {
return $this->configuration[self::JOBS_ARRAY_KEY][$jobName];
}
$jobNameDelimiter = $this->getJobNameDelimiter($jobName);
$jobNameParts = explode($jobNameDelimiter, $jobName);
array_pop($jobNameParts);
if (count($jobNameParts)) {
return $this->checkKeyByJobNameOrItsPart(implode($jobNameDelimiter, $jobNameParts));
}
return null;
}
/**
* @param $jobName
*
* @return mixed
*/
private function getJobNameDelimiter($jobName)
{
foreach (self::JOB_NAME_DELIMITERS as $delimiter) {
if (str_contains($jobName, $delimiter)) {
return $delimiter;
}
}
return self::JOB_NAME_DELIMITERS['dot'];
}
}