Skip to content

Commit

Permalink
Support all SF 4 versions
Browse files Browse the repository at this point in the history
  • Loading branch information
vtsykun committed Jan 17, 2020
1 parent fede989 commit 4c3ff3b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@ services:
Possible options to configure with tags are:

- `cron` - A cron expression, if empty, the command will run always.
- `lock` - Prevent to run the command again, if prev. command is not finished yet. Example: `lock: true`, `lock: {name: lock1, ttl: 300}`.
- `lock` - Prevent to run the command again, if prev. command is not finished yet. Possible value: `true`, `{name: lock1, ttl: 300}`.
To use this option need to install symfony [lock component](https://symfony.com/doc/4.4/components/lock.html)
- `async` - Run command in the new process without blocking main thread.
- `arguments` - Array of arguments, used to run symfony console commands or pass arguments to handler.
- `priority` - Sorting priority.
- `group` - Group name, see Cron Grouping section.
- `messenger` - Send jobs into Messenger Bus. Default `false`. You also can specify transport here `messenger: {routing: async}`,
- `messenger` - Send jobs into Messenger Bus. Default `false`. You also can specify transport here `{routing: async}`,
see [Symfony Routing Messages to a Transport](https://symfony.com/doc/current/messenger.html#routing-messages-to-a-transport)

#### Symfony console command
Expand Down Expand Up @@ -174,7 +174,7 @@ okvpn_cron:
lock: true # Default false
messenger: true # Handle all jobs with symfony messenger bus.

# Stamps it's markers that will add to each tasks. Used by Middleware's, see customization example
# Stamps it's markers that will add to each tasks.
with_stamps:
- 'Packagist\WebBundle\Cron\WorkerStamp'

Expand Down
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
}
],
"require": {
"php": "^7.2.5",
"symfony/framework-bundle": "^3.4|^4.3|^5.0",
"php": ">=7.2",
"symfony/framework-bundle": "^3.4|^4.0|^5.0",
"dragonmantank/cron-expression": "^2.0"
},
"autoload": {
Expand All @@ -43,6 +43,9 @@
"dev-master": "1.0-dev"
}
},
"conflict": {
"symfony/messenger": "<4.3"
},
"suggest": {
"symfony/process": "For using shell commands",
"symfony/lock": "For locking jobs",
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/CompilerPass/CronPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private function normalizeTask(ContainerBuilder $container, array $task): array
{
if (isset($task['lock']) && $task['lock']) {
if (is_scalar($task['lock'])) {
$task['lock']['name'] = is_string($task['lock']) ? $task['lock'] : $task['command'];
$task['lock'] = ['name' => is_string($task['lock']) ? $task['lock'] : $task['command']];
}
if (!isset($task['lock']['name']) || !is_string($task['lock']['name'])) {
$task['lock']['name'] = $task['command'];
Expand Down
2 changes: 1 addition & 1 deletion src/Middleware/MessengerEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function handle(ScheduleEnvelope $envelope, StackInterface $stack): Sched
throw new \LogicException('To use messenger cron handler you need enable/install "symfony/messenger" component and configure default_bus');
}

$message = new CronMessage($envelope);
$message = new CronMessage($envelope->without(MessengerStamp::class));
$routing = $envelope->get(MessengerStamp::class)->getRouting();
$stamps = \array_map(function ($route) {return new RoutingStamp($route);}, $routing);
$this->messageBus->dispatch($message, $stamps);
Expand Down

0 comments on commit 4c3ff3b

Please sign in to comment.