-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
71 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Orisai\Scheduler\Command; | ||
|
||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
final class ExplainCommand extends Command | ||
{ | ||
|
||
public static function getDefaultName(): string | ||
{ | ||
return 'scheduler:explain'; | ||
} | ||
|
||
public static function getDefaultDescription(): string | ||
{ | ||
return 'Explain cron expression'; | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$this->explainSyntax($output); | ||
|
||
return 0; | ||
} | ||
|
||
private function explainSyntax(OutputInterface $output): void | ||
{ | ||
$output->writeln( | ||
<<<'CMD' | ||
<fg=yellow>* * * * *</> | ||
- - - - - | ||
| | | | | | ||
| | | | | | ||
| | | | +----- day of week (0-7) (Sunday = 0 or 7) (or SUN-SAT) | ||
| | | +--------- month (1-12) (or JAN-DEC) | ||
| | +------------- day of month (1-31) | ||
| +----------------- hour (0-23) | ||
+--------------------- minute (0-59) | ||
Each part of expression can also use wildcard, lists, ranges and steps: | ||
- wildcard - <fg=yellow>* * * * *</> - At every minute. | ||
- lists - e.g. <fg=yellow>15,30 * * * *</> - At minute 15 and 30. | ||
- ranges - e.g. <fg=yellow>1-9 * * * *</> - At every minute from 1 through 9. | ||
- steps | ||
- e.g. <fg=yellow>*/5 * * * *</> - At every 5th minute. | ||
- e.g. <fg=yellow>0-30/5 * * * *</> - At every 5th minute from 0 through 30. | ||
- combinations - e.g. <fg=yellow>0-14,30-44 * * * *</> - At every minute from 0 through 14 and every minute from 30 through 44. | ||
You can also use macro instead of an expression: | ||
- <fg=yellow>@yearly</>, <fg=yellow>@annually</> - Run once a year, midnight, Jan. 1 - <fg=yellow>0 0 1 1 *</> | ||
- <fg=yellow>@monthly</> - Run once a month, midnight, first of month - <fg=yellow>0 0 1 * *</> | ||
- <fg=yellow>@weekly</> - Run once a week, midnight on Sun - <fg=yellow>0 0 * * 0</> | ||
- <fg=yellow>@daily</>, <fg=yellow>@midnight</> - Run once a day, midnight - <fg=yellow>0 0 * * *</> | ||
- <fg=yellow>@hourly</> - Run once an hour, first minute - <fg=yellow>0 * * * *</> | ||
Although they are not part of cron expression syntax, you can also add to job: | ||
- seconds - repeat job every n seconds | ||
- timezone - run only when cron expression matches within given timezone | ||
CMD, | ||
); | ||
} | ||
|
||
} |