-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added "scheduler" command for show scheduled task list
- Loading branch information
Showing
8 changed files
with
106 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Luzrain\PHPStreamServer\Internal\SystemPlugin\Command; | ||
|
||
use Luzrain\PHPStreamServer\Internal\Console\Command; | ||
use Luzrain\PHPStreamServer\Internal\Console\Options; | ||
use Luzrain\PHPStreamServer\Internal\Console\Table; | ||
use Luzrain\PHPStreamServer\Internal\Scheduler\Trigger\TriggerFactory; | ||
use Luzrain\PHPStreamServer\Internal\SystemPlugin\ServerStatus\PeriodicWorkerInfo; | ||
use Luzrain\PHPStreamServer\Internal\SystemPlugin\ServerStatus\ServerStatus; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class SchedulerCommand extends Command | ||
{ | ||
protected const COMMAND = 'scheduler'; | ||
protected const DESCRIPTION = 'Show scheduler map'; | ||
|
||
public function execute(Options $options): int | ||
{ | ||
echo "❯ Scheduler\n"; | ||
|
||
if(!$this->masterProcess->isRunning()) { | ||
echo " <color;bg=yellow> ! </> <color;fg=yellow>Server is not running</>\n"; | ||
|
||
return 0; | ||
} | ||
|
||
$status = $this->masterProcess->get(ServerStatus::class); | ||
\assert($status instanceof ServerStatus); | ||
|
||
if ($status->getPeriodicTasksCount() > 0) { | ||
echo (new Table(indent: 1)) | ||
->setHeaderRow([ | ||
'User', | ||
'Worker', | ||
'Schedule', | ||
'Next run', | ||
'Status', | ||
]) | ||
->addRows(\array_map(array: $status->getPeriodicWorkers(), callback: static fn (PeriodicWorkerInfo $w) => [ | ||
$w->user === 'root' ? $w->user : "<color;fg=gray>{$w->user}</>", | ||
$w->name, | ||
$w->schedule ?: '-', | ||
$w->nextRunDate?->format('Y-m-d H:i:s') ?? '<color;fg=gray>-</>', | ||
match(true) { | ||
$w->nextRunDate !== null => '[<color;fg=green>OK</>]', | ||
default => '[<color;fg=red>ERROR</>]', | ||
}, | ||
])); | ||
} else { | ||
echo " <color;bg=yellow> ! </> <color;fg=yellow>There are no scheduled tasks</>\n"; | ||
} | ||
|
||
return 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
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,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Luzrain\PHPStreamServer\Message; | ||
|
||
use Luzrain\PHPStreamServer\Message; | ||
|
||
/** | ||
* @implements Message<void> | ||
*/ | ||
final readonly class ProcessScheduledEvent implements Message | ||
{ | ||
public function __construct( | ||
public int $id, | ||
public \DateTimeInterface|null $nextRunDate, | ||
) { | ||
} | ||
} |