-
-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathServiceJobLoaderListener.php
More file actions
40 lines (33 loc) · 1.09 KB
/
ServiceJobLoaderListener.php
File metadata and controls
40 lines (33 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
declare(strict_types=1);
namespace Shapecode\Bundle\CronBundle\EventListener;
use Shapecode\Bundle\CronBundle\Collection\CronJobMetadataCollection;
use Shapecode\Bundle\CronBundle\Domain\CronJobMetadata;
use Shapecode\Bundle\CronBundle\Event\LoadJobsEvent;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
#[AsEventListener]
final readonly class ServiceJobLoaderListener
{
private CronJobMetadataCollection $metadataCollection;
public function __construct()
{
$this->metadataCollection = new CronJobMetadataCollection();
}
public function __invoke(LoadJobsEvent $event): void
{
foreach ($this->metadataCollection as $job) {
$event->addJob($job);
}
}
public function addCommand(
string $expression,
Command $command,
string|null $arguments = null,
int $maxInstances = 1,
): void {
$this->metadataCollection->add(
CronJobMetadata::createByCommand($expression, $command, $arguments, $maxInstances),
);
}
}