diff --git a/.docs/README.md b/.docs/README.md
index 9fcf7b6..dc02a10 100644
--- a/.docs/README.md
+++ b/.docs/README.md
@@ -1,4 +1,4 @@
-# Contributte Scheduler
+# Contributte Executor
Executing php callbacks using cron expression.
@@ -14,29 +14,29 @@ Executing php callbacks using cron expression.
Require package
```bash
-composer require contributte/scheduler
+composer require contributte/executor
```
Register extension
```neon
extensions:
- scheduler: Contributte\Scheduler\DI\SchedulerExtension
+ executor: Contributte\Executor\DI\ExecutorExtension
```
## Configuration
-Set-up crontab. Use the `scheduler:run` command.
+Set-up crontab. Use the `executor:run` command.
```
-* * * * * php path-to-project/console scheduler:run
+* * * * * php path-to-project/console executor:run
```
Optionally, you can set a temp path for storing lock files.
```neon
-scheduler:
- path: '%tempDir%/scheduler'
+executor:
+ path: '%tempDir%/executor'
```
## Jobs
@@ -48,13 +48,13 @@ This package defines 2 types of jobs:
### Callback job
-Register your callbacks under `scheduler.jobs` key.
+Register your callbacks under `executor.jobs` key.
```neon
services:
stats: App\Model\Stats
-scheduler:
+executor:
jobs:
# stats must be registered as service and have method calculate
- { cron: '* * * * *', callback: [ @stats, calculate ] }
@@ -83,7 +83,7 @@ using [crontab.guru](https://crontab.guru).
Create new class which implements `IJob` interface.
```php
-use Contributte\Scheduler\IJob;
+use Contributte\Executor\IJob;
class ScheduledJob implements IJob
{
@@ -118,7 +118,7 @@ Register your class into `config.neon` as regular services
into [nette dependency-injection container](https://doc.nette.org/en/3.0/dependency-injection).
```neon
-scheduler:
+executor:
jobs:
- App\Model\ScheduledJob
- App\Model\OtherScheduledJob
@@ -130,7 +130,7 @@ You can also reference already registered service.
services:
scheduledJob: App\Model\ScheduledJob
-scheduler:
+executor:
jobs:
- @scheduledJob
```
@@ -140,7 +140,7 @@ scheduler:
If your job class uses `inject*` methods for dependency injection, you can enable auto-injection using the `inject` option:
```neon
-scheduler:
+executor:
jobs:
myJob: {class: App\Model\ScheduledJob, inject: true}
```
@@ -165,7 +165,7 @@ After that you can fire one of these commands.
| Command | Info |
|----------------|-------------------- |
-| scheduler:help | Print cron syntax. |
-| scheduler:list | List all jobs. |
-| scheduler:run | Run all due jobs. |
-| scheduler:force-run | Force run selected scheduler job. |
+| executor:help | Print cron syntax. |
+| executor:list | List all jobs. |
+| executor:run | Run all due jobs. |
+| executor:force-run | Force run selected executor job. |
diff --git a/README.md b/README.md
index 699ea42..d4df205 100644
--- a/README.md
+++ b/README.md
@@ -1,14 +1,14 @@
-
+
-
-
-
-
+
+
+
+
-
-
+
+
@@ -20,10 +20,10 @@ Website 🚀 contributte.org | Contact
## Usage
-To install latest version of `contributte/scheduler` use [Composer](https://getcomposer.org).
+To install latest version of `contributte/executor` use [Composer](https://getcomposer.org).
```bash
-composer require contributte/scheduler
+composer require contributte/executor
```
## Documentation
diff --git a/composer.json b/composer.json
index a05b664..0020ba9 100644
--- a/composer.json
+++ b/composer.json
@@ -1,15 +1,15 @@
{
- "name": "contributte/scheduler",
- "description": "PHP job scheduler (cron) with locking",
+ "name": "contributte/executor",
+ "description": "PHP job executor (cron) with locking",
"keywords": [
"nette",
"cron",
"contributte",
- "scheduler"
+ "executor"
],
"license": "MIT",
"type": "library",
- "homepage": "https://github.com/contributte/scheduler",
+ "homepage": "https://github.com/contributte/executor",
"authors": [
{
"name": "Milan Felix Å ulc",
@@ -35,7 +35,7 @@
},
"autoload": {
"psr-4": {
- "Contributte\\Scheduler\\": "src/"
+ "Contributte\\Executor\\": "src/"
}
},
"autoload-dev": {
diff --git a/ruleset.xml b/ruleset.xml
index a4ef64c..c8cceea 100644
--- a/ruleset.xml
+++ b/ruleset.xml
@@ -7,7 +7,7 @@
-
+
diff --git a/src/CallbackJob.php b/src/CallbackJob.php
index e9eeb37..0d96f12 100644
--- a/src/CallbackJob.php
+++ b/src/CallbackJob.php
@@ -1,6 +1,6 @@
scheduler = $scheduler;
+ $this->executor = $executor;
}
protected function configure(): void
@@ -38,7 +38,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return Command::FAILURE;
}
- $job = $this->scheduler->get($key);
+ $job = $this->executor->get($key);
if ($job === null) {
return Command::FAILURE;
diff --git a/src/Command/HelpCommand.php b/src/Command/HelpCommand.php
index eeeeef8..df4d625 100644
--- a/src/Command/HelpCommand.php
+++ b/src/Command/HelpCommand.php
@@ -1,6 +1,6 @@
scheduler = $scheduler;
+ $this->executor = $executor;
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
- $jobs = $this->scheduler->getAll();
+ $jobs = $this->executor->getAll();
$table = new Table($output);
$table->setHeaders(['Key', 'Type', 'Is due', 'Cron', 'Callback']);
$dateTime = new DateTime();
diff --git a/src/Command/RunCommand.php b/src/Command/RunCommand.php
index a3879b8..d6357a2 100644
--- a/src/Command/RunCommand.php
+++ b/src/Command/RunCommand.php
@@ -1,32 +1,32 @@
scheduler = $scheduler;
+ $this->executor = $executor;
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
- $this->scheduler->run();
+ $this->executor->run();
return Command::SUCCESS;
}
diff --git a/src/DI/SchedulerExtension.php b/src/DI/ExecutorExtension.php
similarity index 74%
rename from src/DI/SchedulerExtension.php
rename to src/DI/ExecutorExtension.php
index d3f4bc4..5a8218f 100644
--- a/src/DI/SchedulerExtension.php
+++ b/src/DI/ExecutorExtension.php
@@ -1,15 +1,15 @@
getContainerBuilder();
$config = $this->config;
- // Scheduler
- $schedulerDefinition = $builder->addDefinition($this->prefix('scheduler'))
- ->setType(IScheduler::class);
+ $executorDefinition = $builder->addDefinition($this->prefix('executor'))
+ ->setType(IExecutor::class);
if ($config->path !== null) {
- $schedulerDefinition->setFactory(LockingScheduler::class, [$config->path]);
+ $executorDefinition->setFactory(LockingExecutor::class, [$config->path]);
} else {
- $schedulerDefinition->setFactory(Scheduler::class);
+ $executorDefinition->setFactory(Executor::class);
}
- // Commands
$builder->addDefinition($this->prefix('runCommand'))
->setFactory(RunCommand::class)
->setAutowired(false);
@@ -81,6 +79,9 @@ public function loadConfiguration(): void
}
$inject = $jobConfig['inject'] ?? false;
+ if (!is_bool($inject)) {
+ throw new InvalidArgumentException(sprintf('Option "inject" of %s > jobs > %s must be boolean', $this->name, $jobName));
+ }
$jobDefinition = $builder->addDefinition($this->prefix('job.' . $jobName))
->setFactory($class)
@@ -100,7 +101,7 @@ public function loadConfiguration(): void
throw new InvalidArgumentException(sprintf('Job %s > jobs > %s must be a string or array', $this->name, $jobName));
}
- $schedulerDefinition->addSetup('add', [$jobDefinition, $jobName]);
+ $executorDefinition->addSetup('add', [$jobDefinition, $jobName]);
}
}
diff --git a/src/Exceptions/LogicalException.php b/src/Exceptions/LogicalException.php
index 0daee93..2b2e5be 100644
--- a/src/Exceptions/LogicalException.php
+++ b/src/Exceptions/LogicalException.php
@@ -1,6 +1,6 @@
getAttributes(AsCommand::class)[0] ?? null;
+ Assert::notNull($attribute);
+
+ $arguments = $attribute->getArguments();
+ Assert::same($name, $arguments['name'] ?? null);
+ Assert::same([], $arguments['aliases'] ?? []);
+}
diff --git a/tests/Cases/DI/SchedulerExtension.phpt b/tests/Cases/DI/ExecutorExtension.phpt
similarity index 66%
rename from tests/Cases/DI/SchedulerExtension.phpt
rename to tests/Cases/DI/ExecutorExtension.phpt
index c111ea8..e099d6d 100644
--- a/tests/Cases/DI/SchedulerExtension.phpt
+++ b/tests/Cases/DI/ExecutorExtension.phpt
@@ -2,8 +2,8 @@
namespace Tests\Cases\DI;
-use Contributte\Scheduler\DI\SchedulerExtension;
-use Contributte\Scheduler\IScheduler;
+use Contributte\Executor\DI\ExecutorExtension;
+use Contributte\Executor\IExecutor;
use Contributte\Tester\Toolkit;
use Contributte\Tester\Utils\ContainerBuilder;
use Contributte\Tester\Utils\Neonkit;
@@ -14,17 +14,16 @@ use Tests\Fixtures\InjectableJob;
require_once __DIR__ . '/../../bootstrap.php';
-// Custom parse case
Toolkit::test(function (): void {
$container = ContainerBuilder::of()
->withCompiler(function (Compiler $compiler): void {
- $compiler->addExtension('scheduler', new SchedulerExtension());
+ $compiler->addExtension('executor', new ExecutorExtension());
$compiler->addConfig(Neonkit::load(<<<'NEON'
services:
callbackJob: Tests\Fixtures\CallbackJob
scheduledJob: Tests\Fixtures\CustomJob
- scheduler:
+ executor:
jobs:
- {cron: '* * * * *', callback: Tests\Fixtures\CallbackJob::foo}
- {cron: '* * * * *', callback: [@callbackJob, bar]}
@@ -34,51 +33,49 @@ Toolkit::test(function (): void {
));
})->build();
- $scheduler = $container->getByType(IScheduler::class);
- Assert::type(IScheduler::class, $scheduler);
- Assert::count(4, $scheduler->getAll());
+ $executor = $container->getByType(IExecutor::class);
+ Assert::type(IExecutor::class, $executor);
+ Assert::count(4, $executor->getAll());
});
-// Test job with class config
Toolkit::test(function (): void {
$container = ContainerBuilder::of()
->withCompiler(function (Compiler $compiler): void {
- $compiler->addExtension('scheduler', new SchedulerExtension());
+ $compiler->addExtension('executor', new ExecutorExtension());
$compiler->addConfig(Neonkit::load(<<<'NEON'
- scheduler:
+ executor:
jobs:
myJob: {class: Tests\Fixtures\CustomJob}
NEON
));
})->build();
- $scheduler = $container->getByType(IScheduler::class);
- Assert::type(IScheduler::class, $scheduler);
- Assert::count(1, $scheduler->getAll());
+ $executor = $container->getByType(IExecutor::class);
+ Assert::type(IExecutor::class, $executor);
+ Assert::count(1, $executor->getAll());
});
-// Test job with inject: true
Toolkit::test(function (): void {
$container = ContainerBuilder::of()
->withCompiler(function (Compiler $compiler): void {
- $compiler->addExtension('scheduler', new SchedulerExtension());
+ $compiler->addExtension('executor', new ExecutorExtension());
$compiler->addExtension('inject', new InjectExtension());
$compiler->addConfig(Neonkit::load(<<<'NEON'
services:
dependency: Tests\Fixtures\SomeDependency
- scheduler:
+ executor:
jobs:
injectableJob: {class: Tests\Fixtures\InjectableJob, inject: true}
NEON
));
})->build();
- $scheduler = $container->getByType(IScheduler::class);
- Assert::type(IScheduler::class, $scheduler);
- Assert::count(1, $scheduler->getAll());
+ $executor = $container->getByType(IExecutor::class);
+ Assert::type(IExecutor::class, $executor);
+ Assert::count(1, $executor->getAll());
- $jobs = $scheduler->getAll();
+ $jobs = $executor->getAll();
$job = reset($jobs);
Assert::type(InjectableJob::class, $job);
Assert::notNull($job->getDependency());
diff --git a/tests/Fixtures/CustomJob.php b/tests/Fixtures/CustomJob.php
index 22a9446..880dbe6 100644
--- a/tests/Fixtures/CustomJob.php
+++ b/tests/Fixtures/CustomJob.php
@@ -2,7 +2,7 @@
namespace Tests\Fixtures;
-use Contributte\Scheduler\IJob;
+use Contributte\Executor\IJob;
use DateTime;
final class CustomJob implements IJob
diff --git a/tests/Fixtures/InjectableJob.php b/tests/Fixtures/InjectableJob.php
index dacdf71..60719ee 100644
--- a/tests/Fixtures/InjectableJob.php
+++ b/tests/Fixtures/InjectableJob.php
@@ -2,7 +2,7 @@
namespace Tests\Fixtures;
-use Contributte\Scheduler\IJob;
+use Contributte\Executor\IJob;
use DateTime;
final class InjectableJob implements IJob