FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Implemented basic lock component by wachterjohannes · Pull Request #35 · php-task/php-task · GitHub

Implemented basic lock component - #35

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

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

Conversation

wachterjohannes commented May 12, 2017
edited
Loading

Copy link
Copy Markdown
Member

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

Comment thread src/Task/Lock/Storage/FileLock.php Outdated
*/
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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

check styleci config

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Comment thread src/Task/Lock/Storage/FileLock.php Outdated
/**
* 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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

FileLockStorage?

Comment thread src/Task/Lock/StorageInterface.php Outdated
/**
* 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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Copy link
Copy Markdown
Member Author

@danrot fixed

danrot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Copy link
Copy Markdown
Member Author

@danrot fixed

wachterjohannes force-pushed the feature/lock branch 3 times, most recently from 6e15480 to e3373f0 Compare May 18, 2017 06:35
alexander-schranz merged commit 34748a4 into master May 18, 2017
wachterjohannes deleted the feature/lock branch May 18, 2017 07:54
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL