|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Stu\Module\Tick\Spacecraft; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
8
|
|
|
use Override; |
|
|
|
|
|
|
9
|
|
|
use Stu\Component\Game\SemaphoreConstants; |
|
|
|
|
|
|
10
|
|
|
use Stu\Module\Control\SemaphoreUtilInterface; |
|
11
|
|
|
use Stu\Module\Logging\LoggerUtilFactoryInterface; |
|
12
|
|
|
use Stu\Module\Logging\LoggerUtilInterface; |
|
13
|
|
|
use Stu\Module\Tick\Lock\LockManagerInterface; |
|
14
|
|
|
use Stu\Module\Tick\Lock\LockTypeEnum; |
|
15
|
|
|
use Stu\Module\Tick\Spacecraft\ManagerComponent\ManagerComponentInterface; |
|
16
|
|
|
|
|
17
|
|
|
final class SpacecraftTickManager implements SpacecraftTickManagerInterface |
|
18
|
|
|
{ |
|
19
|
|
|
private LoggerUtilInterface $loggerUtil; |
|
20
|
|
|
|
|
21
|
|
|
/** @param array<ManagerComponentInterface> $components */ |
|
22
|
1 |
|
public function __construct( |
|
23
|
|
|
private SemaphoreUtilInterface $semaphoreUtil, |
|
24
|
|
|
private LockManagerInterface $lockManager, |
|
25
|
|
|
private EntityManagerInterface $entityManager, |
|
26
|
|
|
private array $components, |
|
27
|
|
|
LoggerUtilFactoryInterface $loggerUtilFactory |
|
28
|
|
|
) { |
|
29
|
1 |
|
$this->loggerUtil = $loggerUtilFactory->getLoggerUtil(true); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
#[Override] |
|
33
|
|
|
public function work(bool $doCommit = false): void |
|
34
|
|
|
{ |
|
35
|
|
|
$this->setLock(1); |
|
36
|
|
|
|
|
37
|
|
|
try { |
|
38
|
|
|
foreach ($this->components as $component) { |
|
39
|
|
|
$startTime = microtime(true); |
|
40
|
|
|
$component->work(); |
|
41
|
|
|
|
|
42
|
|
|
if ($this->loggerUtil->doLog()) { |
|
43
|
|
|
$endTime = microtime(true); |
|
44
|
|
|
$this->loggerUtil->log(sprintf("\t\t%s, seconds: %F", get_class($component), $endTime - $startTime)); |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
if ($doCommit) { |
|
49
|
|
|
$this->entityManager->flush(); |
|
50
|
|
|
$this->entityManager->commit(); |
|
51
|
|
|
} |
|
52
|
|
|
} finally { |
|
53
|
|
|
$this->clearLock(1); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
private function setLock(int $batchGroupId): void |
|
58
|
|
|
{ |
|
59
|
|
|
//main ship sema on |
|
60
|
|
|
$mainSema = $this->semaphoreUtil->acquireSemaphore(SemaphoreConstants::MAIN_SHIP_SEMAPHORE_KEY); |
|
61
|
|
|
|
|
62
|
|
|
$this->lockManager->setLock($batchGroupId, LockTypeEnum::SHIP_GROUP); |
|
63
|
|
|
|
|
64
|
|
|
//main ship sema off |
|
65
|
|
|
$this->semaphoreUtil->releaseSemaphore($mainSema); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
private function clearLock(int $batchGroupId): void |
|
69
|
|
|
{ |
|
70
|
|
|
$this->lockManager->clearLock($batchGroupId, LockTypeEnum::SHIP_GROUP); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
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