-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
coverage->100%, refactor priorities, add more tests to prioritypool (#19
) * coverage->100%, refactor priorities, add more tests to prioritypool * fix some scruitinzer stuff
- Loading branch information
Harry Bragg
committed
Sep 25, 2018
1 parent
b053045
commit 84ccec5
Showing
15 changed files
with
370 additions
and
92 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
/** | ||
* This file is part of graze/parallel-process. | ||
* | ||
* Copyright © 2018 Nature Delivered Ltd. <https://www.graze.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @license https://github.com/graze/parallel-process/blob/master/LICENSE.md | ||
* @link https://github.com/graze/parallel-process | ||
*/ | ||
|
||
namespace Graze\ParallelProcess\Event; | ||
|
||
use Graze\ParallelProcess\PrioritisedInterface; | ||
use Symfony\Component\EventDispatcher\Event; | ||
|
||
class PriorityChangedEvent extends Event | ||
{ | ||
const CHANGED = 'priority.changed'; | ||
|
||
/** @var PrioritisedInterface */ | ||
private $item; | ||
/** @var float */ | ||
private $priority; | ||
/** @var float|null */ | ||
private $oldPriority; | ||
|
||
/** | ||
* RunEvent constructor. | ||
* | ||
* @param PrioritisedInterface $item | ||
* @param float $priority | ||
* @param float|null $oldPriority | ||
*/ | ||
public function __construct(PrioritisedInterface $item, $priority, $oldPriority = null) | ||
{ | ||
$this->item = $item; | ||
$this->priority = $priority; | ||
$this->oldPriority = $oldPriority; | ||
} | ||
|
||
/** | ||
* @return PrioritisedInterface | ||
*/ | ||
public function getItem() | ||
{ | ||
return $this->item; | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace Graze\ParallelProcess; | ||
|
||
interface PrioritisedInterface | ||
{ | ||
/** | ||
* Get the priority for this item. The higher the number the higher the priority | ||
* | ||
* @return float | ||
*/ | ||
public function getPriority(); | ||
|
||
/** | ||
* Fluent call for setting the priority. | ||
* | ||
* @param float $priority The higher the number the higher the priority | ||
* | ||
* @return $this | ||
*/ | ||
public function setPriority($priority); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace Graze\ParallelProcess; | ||
|
||
use Graze\ParallelProcess\Event\DispatcherInterface; | ||
use Graze\ParallelProcess\Event\PriorityChangedEvent; | ||
|
||
trait PrioritisedTrait | ||
{ | ||
/** @var float */ | ||
protected $priority; | ||
|
||
/** | ||
* @param float $priority | ||
* | ||
* @return $this | ||
*/ | ||
public function setPriority($priority) | ||
{ | ||
$oldPriority = $this->priority; | ||
$this->priority = $priority; | ||
if (!($this instanceof RunInterface && $this->hasStarted()) | ||
&& method_exists($this, 'dispatch') | ||
&& $this instanceof PrioritisedInterface) { | ||
$this->dispatch(PriorityChangedEvent::CHANGED, new PriorityChangedEvent($this, $priority, $oldPriority)); | ||
} | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return float | ||
*/ | ||
public function getPriority() | ||
{ | ||
return $this->priority; | ||
} | ||
} |
Oops, something went wrong.