Skip to content

Implemented basic lock component#35

Merged
alexander-schranz merged 7 commits intomasterfrom
feature/lock
May 18, 2017
Merged

Implemented basic lock component#35
alexander-schranz merged 7 commits intomasterfrom
feature/lock

Conversation

@wachterjohannes
Copy link
Copy Markdown
Member

@wachterjohannes wachterjohannes commented May 12, 2017

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

*/
private function getFileName($key)
{
return $this->lockPath . DIRECTORY_SEPARATOR . preg_replace('/[^a-zA-Z]/', '_', $key) . '.lock';
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0-9

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]);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check styleci config

@wachterjohannes
Copy link
Copy Markdown
Member Author

@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.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

/**
* Save locks in the filesystem.
*/
class FileLock implements StorageInterface
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FileLockStorage?

/**
* Interface for lock storage.
*/
interface StorageInterface
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LockStorageInterface?

* @param mixed $result
*
* @return TaskExecutionInterface
*/
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Methods should be named like verbs.

* @param \Exception $exception
*
* @return TaskExecutionInterface
*/
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Methods should be named like verbs.

* @return TaskExecutionInterface
*/
public function findScheduled();
public function findNextScheduled(\DateTime $dateTime = null);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BC break?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@wachterjohannes
Copy link
Copy Markdown
Member Author

@danrot fixed

Copy link
Copy Markdown

@danrot danrot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
{
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't you also add a nice error message here?

*/
class LockNotAcquiredException extends LockConflictException
{
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, wouldn't a message be nice?

@wachterjohannes
Copy link
Copy Markdown
Member Author

@danrot fixed

@wachterjohannes wachterjohannes force-pushed the feature/lock branch 3 times, most recently from 6e15480 to e3373f0 Compare May 18, 2017 06:35
@alexander-schranz alexander-schranz merged commit 34748a4 into master May 18, 2017
@wachterjohannes wachterjohannes deleted the feature/lock branch May 18, 2017 07:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants