-
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 #6 from hschimpf/1.x-dev
ProgressBar with Enhancements for release
- Loading branch information
Showing
22 changed files
with
1,011 additions
and
203 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,101 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace HDSSolutions\Console\Parallel\Contracts; | ||
|
||
use HDSSolutions\Console\Parallel\ProcessedTask; | ||
|
||
interface ParallelWorker { | ||
|
||
/** | ||
* ## Worker has not yet started | ||
*/ | ||
public const STATE_New = 0; | ||
|
||
/** | ||
* ## Worker is currently running | ||
*/ | ||
public const STATE_Running = 1; | ||
|
||
/** | ||
* ## Worker has finished execution | ||
*/ | ||
public const STATE_Finished = 2; | ||
|
||
/** | ||
* ## Available states of the Worker | ||
*/ | ||
public const STATES = [ | ||
self::STATE_New, | ||
self::STATE_Running, | ||
self::STATE_Finished, | ||
]; | ||
|
||
/** | ||
* Returns the current state of the Worker | ||
* | ||
* @return int Current Worker state | ||
* @see ParallelWorker::STATES | ||
*/ | ||
public function getState(): int; | ||
|
||
/** | ||
* Begin execution of this Worker, calling the `process()` method | ||
* | ||
* @param mixed ...$args Task data to pass to the Worker | ||
*/ | ||
public function start(...$args): void; | ||
|
||
/** | ||
* Associates a text with a named placeholder. | ||
* | ||
* @param string $message The text to associate with the placeholder | ||
* @param string $name The name of the placeholder | ||
*/ | ||
public function setMessage(string $message, string $name = 'message'): void; | ||
|
||
/** | ||
* Advances the progress output X steps. | ||
* | ||
* @param int $steps Number of steps to advance | ||
*/ | ||
public function advance(int $steps = 1): void; | ||
|
||
/** | ||
* Moves the progress output to a specific step. | ||
* | ||
* @param int $step Step to move progress to | ||
*/ | ||
public function setProgress(int $step): void; | ||
|
||
/** | ||
* Outputs the current progress string. | ||
*/ | ||
public function display(): void; | ||
|
||
/** | ||
* Removes the progress bar from the current line. | ||
* | ||
* This is useful if you wish to write some output | ||
* while a progress bar is running. | ||
* Call display() to show the progress bar again. | ||
*/ | ||
public function clear(): void; | ||
|
||
/** | ||
* @return ?float Time when Worker started processing the Task, null if Worker didn't start yet | ||
*/ | ||
public function getStartedAt(): ?float; | ||
|
||
/** | ||
* @return ?float Time when Worker finished processing the Task, null if Worker didn't finish yet | ||
*/ | ||
public function getFinishedAt(): ?float; | ||
|
||
/** | ||
* Returns the processed task | ||
* | ||
* @return ProcessedTask Processed task | ||
*/ | ||
public function getProcessedTask(): ProcessedTask; | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
src/Parallel/Internals/Messages/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,16 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace HDSSolutions\Console\Parallel\Internals\Messages; | ||
|
||
final class ProgressBarActionMessage { | ||
|
||
/** | ||
* @param string $action | ||
* @param array $args | ||
*/ | ||
public function __construct( | ||
public string $action, | ||
public array $args, | ||
) {} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
src/Parallel/Internals/Messages/ProgressBarRegistrationMessage.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,16 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace HDSSolutions\Console\Parallel\Internals\Messages; | ||
|
||
final class ProgressBarRegistrationMessage { | ||
|
||
/** | ||
* @param string $worker | ||
* @param int $steps | ||
*/ | ||
public function __construct( | ||
public string $worker, | ||
public int $steps = 0, | ||
) {} | ||
|
||
} |
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,12 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace HDSSolutions\Console\Parallel\Internals\Messages; | ||
|
||
final class StatsReportMessage { | ||
|
||
public function __construct( | ||
public string $worker_id, | ||
public int $memory_usage, | ||
) {} | ||
|
||
} |
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,30 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace HDSSolutions\Console\Parallel\Internals; | ||
|
||
final class PendingTask { | ||
|
||
/** | ||
* @param RegisteredWorker $registered_worker Registered Worker that will process this task | ||
* @param mixed $data Data of the Task | ||
*/ | ||
public function __construct( | ||
private RegisteredWorker $registered_worker, | ||
private mixed $data = null, | ||
) {} | ||
|
||
/** | ||
* @return RegisteredWorker Registered Worker | ||
*/ | ||
public function getRegisteredWorker(): RegisteredWorker { | ||
return $this->registered_worker; | ||
} | ||
|
||
/** | ||
* @return mixed Data of the Task | ||
*/ | ||
public function getData(): mixed { | ||
return $this->data; | ||
} | ||
|
||
} |
Oops, something went wrong.