Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify RunCommand's dependencies #5569

Merged
merged 3 commits into from
Mar 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
exclude:
- php-version: '8.2'
sw-version: 'v4.8.12'
max-parallel: 12
max-parallel: 20
fail-fast: false
env:
SW_VERSION: ${{ matrix.sw-version }}
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG-3.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- [#5544](https://github.com/hyperf/hyperf/pull/5554) Cancel `grpc-server`'s dependency on `hyperf/rpc`.
- [#5550](https://github.com/hyperf/hyperf/pull/5550) Optimized code for crontab parser and coordinator timer.
- [#5566](https://github.com/hyperf/hyperf/pull/5566) Optimized the type hint to `nullable` for schemas which generated by `cmd`.
- [#5569](https://github.com/hyperf/hyperf/pull/5569) Simplify RunCommand's dependencies.

# v3.0.12 - 2023-03-20

Expand Down
20 changes: 8 additions & 12 deletions src/crontab/src/Command/RunCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,18 @@

class RunCommand extends Command
{
protected Scheduler $scheduler;

protected Executor $executor;

protected ConfigInterface $config;

public function __construct(protected ContainerInterface $container)
{
parent::__construct('crontab:run');
}

public function handle()
{
$this->scheduler = $this->container->get(Scheduler::class);
$this->executor = $this->container->get(Executor::class);
$this->config = $this->container->get(ConfigInterface::class);
$config = $this->container->get(ConfigInterface::class);
$scheduler = $this->container->get(Scheduler::class);
$executor = $this->container->get(Executor::class);

if ($this->config->get('crontab.enable', false)) {
if ($config->get('crontab.enable', false)) {
throw new InvalidArgumentException('Crontab is already disabled, please enable it first.');
}

Expand All @@ -48,10 +42,12 @@ public function handle()
$this->line('Triggering Crontab', 'info');

/** @var Crontab[] $crontabs */
$crontabs = $this->scheduler->schedule();
$crontabs = $scheduler->schedule();

foreach ($crontabs as $crontab) {
$this->executor->execute($crontab);
$executor->execute($crontab);
}

foreach ($crontabs as $crontab) {
$crontab->wait();
}
Expand Down