-
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathAbstractJobRunner.php
More file actions
34 lines (25 loc) · 988 Bytes
/
AbstractJobRunner.php
File metadata and controls
34 lines (25 loc) · 988 Bytes
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
<?php
declare(strict_types=1);
namespace AlmaviaCX\Bundle\IbexaImportExport\Job;
use AlmaviaCX\Bundle\IbexaImportExport\Event\ResetJobRunEvent;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
abstract class AbstractJobRunner implements JobRunnerInterface
{
protected EventDispatcherInterface $eventDispatcher;
public function __construct(EventDispatcherInterface $eventDispatcher)
{
$this->eventDispatcher = $eventDispatcher;
}
public function __invoke(Job $job, int $batchLimit = -1, bool $reset = false): int
{
if ($reset || in_array($job->getStatus(), [Job::STATUS_COMPLETED, Job::STATUS_CANCELED])) {
$this->eventDispatcher->dispatch(new ResetJobRunEvent($job));
$job->reset();
}
if (!$job->canRun()) {
return $job->getStatus();
}
return $this->run($job, $batchLimit);
}
abstract protected function run(Job $job, int $batchLimit = -1): int;
}