-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from hschimpf/feature/decoupled-runner
[v2.0] Framework Redesign
- Loading branch information
Showing
55 changed files
with
2,140 additions
and
973 deletions.
There are no files selected for viewing
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
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,86 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace HDSSolutions\Console\Parallel\Contracts; | ||
|
||
interface Task { | ||
|
||
/** | ||
* ## Task has not yet been processed | ||
*/ | ||
public const STATE_Pending = 0; | ||
|
||
/** | ||
* ## Task processing is starting | ||
*/ | ||
public const STATE_Starting = 1; | ||
|
||
/** | ||
* ## Task is being currently processed | ||
*/ | ||
public const STATE_Processing = 2; | ||
|
||
/** | ||
* ## Task has been processed | ||
*/ | ||
public const STATE_Processed = 3; | ||
|
||
/** | ||
* ## Available states of the Task | ||
*/ | ||
public const STATES = [ | ||
self::STATE_Pending, | ||
self::STATE_Starting, | ||
self::STATE_Processing, | ||
self::STATE_Processed, | ||
]; | ||
|
||
/** | ||
* @return int Identifier of the task | ||
*/ | ||
public function getIdentifier(): int; | ||
|
||
/** | ||
* @return string Worker class assigned to process this Task | ||
*/ | ||
public function getWorkerClass(): string; | ||
|
||
/** | ||
* @return int Identifier of the registered worker | ||
* @internal | ||
*/ | ||
public function getWorkerId(): int; | ||
|
||
/** | ||
* @return mixed Data of the Task | ||
*/ | ||
public function getData(): mixed; | ||
|
||
/** | ||
* Returns the current state of the Task | ||
* | ||
* @return int Current Task state | ||
* @see Task::STATES | ||
*/ | ||
public function getState(): int; | ||
|
||
/** | ||
* @return bool True if the task is pending | ||
*/ | ||
public function isPending(): bool; | ||
|
||
/** | ||
* @return bool True if the task is being currently processed | ||
*/ | ||
public function isBeingProcessed(): bool; | ||
|
||
/** | ||
* @return bool True if the Task was processed | ||
*/ | ||
public function wasProcessed(): bool; | ||
|
||
/** | ||
* @return mixed Result of the Task | ||
*/ | ||
public function getResult(): mixed; | ||
|
||
} |
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,32 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace HDSSolutions\Console\Parallel\Contracts; | ||
|
||
interface TwoWayChannel { | ||
|
||
/** | ||
* Shall receive a value from input channel | ||
* | ||
* @return mixed | ||
*/ | ||
public function receive(): mixed; | ||
|
||
/** | ||
* Shall send the given value to output channel | ||
* | ||
* @param mixed $value Value to send | ||
* | ||
* @return mixed | ||
*/ | ||
public function send(mixed $value): mixed; | ||
|
||
/** | ||
* Shall send true as value to output channel | ||
* | ||
* @return bool | ||
*/ | ||
public function release(): bool; | ||
|
||
public function close(): void; | ||
|
||
} |
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,35 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace HDSSolutions\Console\Parallel\Exceptions; | ||
|
||
use Throwable; | ||
|
||
final class ParallelException { | ||
|
||
private string $message; | ||
|
||
private string $file; | ||
|
||
private int $line; | ||
|
||
public function __construct( | ||
Throwable $e, | ||
) { | ||
$this->message = $e->getMessage(); | ||
$this->file = $e->getFile(); | ||
$this->line = $e->getLine(); | ||
} | ||
|
||
public function getMessage(): string { | ||
return $this->message; | ||
} | ||
|
||
public function getFile(): string { | ||
return $this->file; | ||
} | ||
|
||
public function getLine(): int { | ||
return $this->line; | ||
} | ||
|
||
} |
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,26 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace HDSSolutions\Console\Parallel\Internals\Commands; | ||
|
||
use RuntimeException; | ||
|
||
abstract class ParallelCommandMessage { | ||
|
||
/** | ||
* @param string $action Action to execute | ||
* @param array $args Arguments to pass to the action | ||
*/ | ||
public function __construct( | ||
private string $action, | ||
private array $args = [], | ||
) {} | ||
|
||
public function __get(string $name) { | ||
if ( !property_exists($this, $name)) { | ||
throw new RuntimeException(sprintf('Invalid property "%s"', $name)); | ||
} | ||
|
||
return $this->$name; | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
src/Internals/Commands/ProgressBar/EnableProgressBarMessage.php
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,21 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace HDSSolutions\Console\Parallel\Internals\Commands\ProgressBar; | ||
|
||
use HDSSolutions\Console\Parallel\Internals\Commands\ParallelCommandMessage; | ||
use HDSSolutions\Console\Parallel\Internals\Runner; | ||
|
||
/** | ||
* Message sent to {@see Runner} to execute {@see Runner::enableProgressBar()} action | ||
*/ | ||
final class EnableProgressBarMessage extends ParallelCommandMessage { | ||
|
||
/** | ||
* @param string $identifier | ||
* @param int $steps | ||
*/ | ||
public function __construct(string $identifier, int $steps) { | ||
parent::__construct('enable_progress_bar', [ $identifier, $steps ]); | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
src/Internals/Commands/ProgressBar/ProgressBarActionMessage.php
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,20 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace HDSSolutions\Console\Parallel\Internals\Commands\ProgressBar; | ||
|
||
use HDSSolutions\Console\Parallel\Internals\Commands\ParallelCommandMessage; | ||
|
||
/** | ||
* Message sent to {@see ProgressBarWorker} to execute {@see ProgressBarWorker::progressBarAction()} | ||
*/ | ||
final class ProgressBarActionMessage extends ParallelCommandMessage { | ||
|
||
/** | ||
* @param string $action | ||
* @param array $args | ||
*/ | ||
public function __construct(string $action, array $args) { | ||
parent::__construct('progress_bar_action', [ $action, $args ]); | ||
} | ||
|
||
} |
Oops, something went wrong.