Skip to content

Commit

Permalink
Added cluster usage example
Browse files Browse the repository at this point in the history
  • Loading branch information
vtsykun committed Jan 29, 2023
1 parent bab17d3 commit 2827ad0
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,42 @@ services:

## Handling cron jobs across a cluster or custom message queue

You can use the cron `$group` to split many scheduled tasks between clusters, see example:

```php
<?php declare(strict_types=1);
namespace App\Cron;

class EntityCronLoader implements ScheduleLoaderInterface
{
public function getSchedules(array $options = []): iterable
{
if (!\in_array($group = $options['group'] ?? 'default', ['default', 'all_chunk']) && !\str_starts_with($group, 'chunk_')) {
return;
}

$chunkId = str_replace('chunk_', '', $group)
foreach ($this->registry->getAllRepos($chunkId) as $name => $repo) {
$expr = '@random ' . $this->getSyncInterval($repo);

yield new ScheduleEnvelope(
'sync:mirrors',
new Model\ScheduleStamp($expr),
new WorkerStamp(true),
new Model\ArgumentsStamp(['mirror' => $name,])
);
}
}
}
```

```
[program:app-cron]
command=/path/to/bin/console okvpn:cron --env=prod --demand --group=chunk_%process_num%
process_name=%(program_name)s_%(process_num)02d
numprocs=1
```

See example of customization
[one](https://github.com/vtsykun/packeton/tree/master/src/Cron/WorkerMiddleware.php),
[two](https://github.com/vtsykun/packeton/tree/master/src/Cron/CronWorker.php)
Expand Down

0 comments on commit 2827ad0

Please sign in to comment.