ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilTestProcessLockerFile.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
28{
29 public const PROCESS_NAME_TEST_START_LOCK_CHECK = 'testStartLockCheck';
30 public const PROCESS_NAME_RANDOM_PASS_BUILD = 'randomPassBuild';
31 public const PROCESS_NAME_TEST_FINISH = 'testFinish';
32
34
39
45 {
46 $this->lockFileStorage = $lockFileStorage;
47 $this->lockFileHandles = [];
48 }
49
54 {
55 parent::onBeforeExecutingTestStartOperation();
56 $this->requestLock(self::PROCESS_NAME_TEST_START_LOCK_CHECK);
57 }
58
63 {
64 $this->releaseLock(self::PROCESS_NAME_TEST_START_LOCK_CHECK);
65 parent::onAfterExecutingTestStartOperation();
66 }
67
71 protected function onBeforeExecutingRandomPassBuildOperation($withTaxonomyTables = false)
72 {
73 parent::onBeforeExecutingRandomPassBuildOperation($withTaxonomyTables);
74 $this->requestLock(self::PROCESS_NAME_RANDOM_PASS_BUILD);
75 }
76
80 protected function onAfterExecutingRandomPassBuildOperation($withTaxonomyTables = false)
81 {
82 $this->releaseLock(self::PROCESS_NAME_RANDOM_PASS_BUILD);
83 parent::onAfterExecutingRandomPassBuildOperation($withTaxonomyTables);
84 }
85
90 {
91 parent::onBeforeExecutingTestStartOperation();
92 $this->requestLock(self::PROCESS_NAME_TEST_FINISH);
93 }
94
99 {
100 $this->releaseLock(self::PROCESS_NAME_TEST_FINISH);
101 parent::onAfterExecutingTestStartOperation();
102 }
103
104 protected function onBeforeExecutingNamedOperation(string $operationDescriptor): void
105 {
106 $this->requestLock($operationDescriptor);
107 parent::onBeforeExecutingNamedOperation($operationDescriptor);
108 }
109
110 protected function onAfterExecutingNamedOperation(string $operationDescriptor): void
111 {
112 $this->releaseLock($operationDescriptor);
113 parent::onAfterExecutingNamedOperation($operationDescriptor);
114 }
115
116 private function requestLock($processName)
117 {
118 $lockFilePath = $this->getLockFilePath($processName);
119 $this->lockFileHandles[$processName] = fopen($lockFilePath, 'w');
120 flock($this->lockFileHandles[$processName], LOCK_EX);
121 }
122
123 private function getLockFilePath($processName): string
124 {
125 $path = $this->lockFileStorage->getAbsolutePath();
126 return $path . '/' . $processName . '.lock';
127 }
128
129 private function releaseLock($processName)
130 {
131 flock($this->lockFileHandles[$processName], LOCK_UN);
132 fclose($this->lockFileHandles[$processName]);
133 }
134}
ilTestProcessLockFileStorage $lockFileStorage
onBeforeExecutingNamedOperation(string $operationDescriptor)
onAfterExecutingRandomPassBuildOperation($withTaxonomyTables=false)
{}
__construct(ilTestProcessLockFileStorage $lockFileStorage)
ilTestProcessLockerFile constructor.
onBeforeExecutingRandomPassBuildOperation($withTaxonomyTables=false)
{}
onAfterExecutingNamedOperation(string $operationDescriptor)
$path
Definition: ltiservices.php:30