Implemented basic lock component#35
Conversation
0f9f5a6 to
58a326a
Compare
7ab6ad7 to
11ff21c
Compare
11ff21c to
55bcb29
Compare
src/Task/Lock/Storage/FileLock.php
Outdated
| */ | ||
| private function getFileName($key) | ||
| { | ||
| return $this->lockPath . DIRECTORY_SEPARATOR . preg_replace('/[^a-zA-Z]/', '_', $key) . '.lock'; |
| function (TaskExecutionInterface $execution) use ($task) { | ||
| return $execution->getTask()->getUuid() === $task->getUuid() | ||
| && in_array($execution->getStatus(), [TaskStatus::PLANNED, TaskStatus::RUNNING]); | ||
| && in_array($execution->getStatus(), [TaskStatus::PLANNED, TaskStatus::RUNNING]); |
55bcb29 to
8497a58
Compare
|
@alexander-schranz fixed |
| * Will be thrown when a conflict is detected: | ||
| * + Already acquired key was acquired. | ||
| * + Not acquired key was released. | ||
| * + Not acquired key was refreshed. |
There was a problem hiding this comment.
Can't you throw more specific exception instead of one for all cases? This way it will be harder to debug as it have to (You can't directly see from the exception if the key was already acquired or not).
src/Task/Lock/Storage/FileLock.php
Outdated
| /** | ||
| * Save locks in the filesystem. | ||
| */ | ||
| class FileLock implements StorageInterface |
src/Task/Lock/StorageInterface.php
Outdated
| /** | ||
| * Interface for lock storage. | ||
| */ | ||
| interface StorageInterface |
| * @param mixed $result | ||
| * | ||
| * @return TaskExecutionInterface | ||
| */ |
| * @param \Exception $exception | ||
| * | ||
| * @return TaskExecutionInterface | ||
| */ |
| * @return TaskExecutionInterface | ||
| */ | ||
| public function findScheduled(); | ||
| public function findNextScheduled(\DateTime $dateTime = null); |
There was a problem hiding this comment.
of course (: I will add an upgrade. This interface is only used for internal usage (TaskRunner) so it should only be important for developers.
| new TaskExecutionEvent($execution->getTask(), $execution) | ||
| ); | ||
| $runTime = new \DateTime(); | ||
|
|
There was a problem hiding this comment.
Is performance a concern here? You are multiplying the database requests this way. Can't you still load all of them at once and keep them in memory before executing them?
There was a problem hiding this comment.
No here is the performance not so important. More important is that the execution is always clean and sync with the database. as you see the implementation before has loaded the whole execution which has to be executed. But in the loop, it was always refreshed because the task could reset (or the listener in the bundle) doctrine. So I change it to this more explicit implementation.
b1b1571 to
9412634
Compare
|
@danrot fixed |
danrot
left a comment
There was a problem hiding this comment.
The rest looks good, but I don't have anything to test, and setting that up is probably quite some work... Can maybe @alexander-schranz test again?
| */ | ||
| class LockAlreadyAcquiredException extends LockConflictException | ||
| { | ||
| } |
There was a problem hiding this comment.
Wouldn't you also add a nice error message here?
| */ | ||
| class LockNotAcquiredException extends LockConflictException | ||
| { | ||
| } |
There was a problem hiding this comment.
Same as above, wouldn't a message be nice?
9412634 to
032c2e3
Compare
|
@danrot fixed |
6e15480 to
e3373f0
Compare
e3373f0 to
aea787f
Compare
4e69e55 to
2fc6ad5
Compare
This PR introduces a simple lock mechanism which blocks all the executions for the related handler when the execution runs.
Docs php-task/docs#5