Skip to content
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
34 changes: 17 additions & 17 deletions .docs/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Contributte Scheduler
# Contributte Executor

Executing php callbacks using cron expression.

Expand All @@ -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
Expand All @@ -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 ] }
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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
Expand All @@ -130,7 +130,7 @@ You can also reference already registered service.
services:
scheduledJob: App\Model\ScheduledJob

scheduler:
executor:
jobs:
- @scheduledJob
```
Expand All @@ -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}
```
Expand All @@ -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. |
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
![](https://heatbadger.now.sh/github/readme/contributte/scheduler/)
![](https://heatbadger.now.sh/github/readme/contributte/executor/)

<p align=center>
<a href="https://github.com/contributte/scheduler/actions"><img src="https://badgen.net/github/checks/contributte/scheduler/master"></a>
<a href="https://codecov.io/gh/contributte/scheduler"><img src="https://badgen.net/codecov/c/github/contributte/scheduler"></a>
<a href="https://packagist.org/packages/contributte/scheduler"><img src="https://badgen.net/packagist/dm/contributte/scheduler"></a>
<a href="https://packagist.org/packages/contributte/scheduler"><img src="https://badgen.net/packagist/v/contributte/scheduler"></a>
<a href="https://github.com/contributte/executor/actions"><img src="https://badgen.net/github/checks/contributte/executor/master"></a>
<a href="https://codecov.io/gh/contributte/executor"><img src="https://badgen.net/codecov/c/github/contributte/executor"></a>
<a href="https://packagist.org/packages/contributte/executor"><img src="https://badgen.net/packagist/dm/contributte/executor"></a>
<a href="https://packagist.org/packages/contributte/executor"><img src="https://badgen.net/packagist/v/contributte/executor"></a>
</p>
<p align=center>
<a href="https://packagist.org/packages/contributte/scheduler"><img src="https://badgen.net/packagist/php/contributte/scheduler"></a>
<a href="https://github.com/contributte/scheduler"><img src="https://badgen.net/github/license/contributte/scheduler"></a>
<a href="https://packagist.org/packages/contributte/executor"><img src="https://badgen.net/packagist/php/contributte/executor"></a>
<a href="https://github.com/contributte/executor"><img src="https://badgen.net/github/license/contributte/executor"></a>
<a href="https://bit.ly/ctteg"><img src="https://badgen.net/badge/support/gitter/cyan"></a>
<a href="https://bit.ly/cttfo"><img src="https://badgen.net/badge/support/forum/yellow"></a>
<a href="https://contributte.org/partners.html"><img src="https://badgen.net/badge/sponsor/donations/F96854"></a>
Expand All @@ -20,10 +20,10 @@ Website 🚀 <a href="https://contributte.org">contributte.org</a> | 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
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -35,7 +35,7 @@
},
"autoload": {
"psr-4": {
"Contributte\\Scheduler\\": "src/"
"Contributte\\Executor\\": "src/"
}
},
"autoload-dev": {
Expand Down
2 changes: 1 addition & 1 deletion ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<rule ref="SlevomatCodingStandard.Files.TypeNameMatchesFileName">
<properties>
<property name="rootNamespaces" type="array">
<element key="src" value="Contributte\Scheduler"/>
<element key="src" value="Contributte\Executor"/>
<element key="tests" value="Tests"/>
</property>
</properties>
Expand Down
2 changes: 1 addition & 1 deletion src/CallbackJob.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types = 1);

namespace Contributte\Scheduler;
namespace Contributte\Executor;

class CallbackJob extends ExpressionJob
{
Expand Down
16 changes: 8 additions & 8 deletions src/Command/ForceRunCommand.php
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
<?php declare(strict_types = 1);

namespace Contributte\Scheduler\Command;
namespace Contributte\Executor\Command;

use Contributte\Scheduler\IScheduler;
use Contributte\Executor\IExecutor;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(
name: 'scheduler:force-run',
description: 'Force run selected scheduler job'
name: 'executor:force-run',
description: 'Force run selected executor job'
)]
class ForceRunCommand extends Command
{

private IScheduler $scheduler;
private IExecutor $executor;

public function __construct(IScheduler $scheduler)
public function __construct(IExecutor $executor)
{
parent::__construct();

$this->scheduler = $scheduler;
$this->executor = $executor;
}

protected function configure(): void
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/Command/HelpCommand.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php declare(strict_types = 1);

namespace Contributte\Scheduler\Command;
namespace Contributte\Executor\Command;

use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(
name: 'scheduler:help',
name: 'executor:help',
description: 'Print cron syntax'
)]
class HelpCommand extends Command
Expand Down
24 changes: 12 additions & 12 deletions src/Command/ListCommand.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php declare(strict_types = 1);

namespace Contributte\Scheduler\Command;
namespace Contributte\Executor\Command;

use Contributte\Scheduler\CallbackJob;
use Contributte\Scheduler\Exceptions\LogicalException;
use Contributte\Scheduler\ExpressionJob;
use Contributte\Scheduler\IJob;
use Contributte\Scheduler\IScheduler;
use Contributte\Executor\CallbackJob;
use Contributte\Executor\Exceptions\LogicalException;
use Contributte\Executor\ExpressionJob;
use Contributte\Executor\IExecutor;
use Contributte\Executor\IJob;
use Cron\CronExpression;
use Nette\Utils\DateTime;
use Symfony\Component\Console\Attribute\AsCommand;
Expand All @@ -16,24 +16,24 @@
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(
name: 'scheduler:list',
description: 'List all scheduler jobs'
name: 'executor:list',
description: 'List all executor jobs'
)]
class ListCommand extends Command
{

private IScheduler $scheduler;
private IExecutor $executor;

public function __construct(IScheduler $scheduler)
public function __construct(IExecutor $executor)
{
parent::__construct();

$this->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();
Expand Down
16 changes: 8 additions & 8 deletions src/Command/RunCommand.php
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
<?php declare(strict_types = 1);

namespace Contributte\Scheduler\Command;
namespace Contributte\Executor\Command;

use Contributte\Scheduler\IScheduler;
use Contributte\Executor\IExecutor;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(
name: 'scheduler:run',
description: 'Run scheduler jobs'
name: 'executor:run',
description: 'Run executor jobs'
)]
class RunCommand extends Command
{

private IScheduler $scheduler;
private IExecutor $executor;

public function __construct(IScheduler $scheduler)
public function __construct(IExecutor $executor)
{
parent::__construct();

$this->scheduler = $scheduler;
$this->executor = $executor;
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->scheduler->run();
$this->executor->run();

return Command::SUCCESS;
}
Expand Down
Loading
Loading