|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Setono\SyliusSchedulerPlugin\Factory; |
|
6
|
|
|
|
|
7
|
|
|
use Setono\SyliusSchedulerPlugin\Model\JobInterface; |
|
8
|
|
|
use Setono\SyliusSchedulerPlugin\Model\ScheduleInterface; |
|
9
|
|
|
use Sylius\Component\Resource\Factory\FactoryInterface; |
|
10
|
|
|
|
|
11
|
|
|
class JobFactory implements JobFactoryInterface |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @var FactoryInterface |
|
15
|
|
|
*/ |
|
16
|
|
|
private $factory; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @param FactoryInterface $factory |
|
20
|
|
|
*/ |
|
21
|
|
|
public function __construct( |
|
22
|
|
|
FactoryInterface $factory |
|
23
|
|
|
) { |
|
24
|
|
|
$this->factory = $factory; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* {@inheritdoc} |
|
29
|
|
|
*/ |
|
30
|
|
|
public function createNew() |
|
31
|
|
|
{ |
|
32
|
|
|
return $this->factory->createNew(); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* {@inheritdoc} |
|
37
|
|
|
*/ |
|
38
|
|
|
public function createRetryJob(JobInterface $job): JobInterface |
|
39
|
|
|
{ |
|
40
|
|
|
/** @var JobInterface $retryJob */ |
|
41
|
|
|
$retryJob = $this->createNew(); |
|
42
|
|
|
$retryJob->setState(JobInterface::STATE_PENDING); |
|
43
|
|
|
$retryJob->setOriginalJob($job); |
|
44
|
|
|
$retryJob->setSchedule($job->getSchedule()); |
|
45
|
|
|
$retryJob->setCommand($job->getCommand()); |
|
|
|
|
|
|
46
|
|
|
$retryJob->setArgs($job->getArgs()); |
|
47
|
|
|
|
|
48
|
|
|
$retryJob->setQueue($job->getQueue()); |
|
49
|
|
|
$retryJob->setPriority($job->getPriority()); |
|
50
|
|
|
|
|
51
|
|
|
$retryJob->setMaxRuntime($job->getMaxRuntime()); |
|
52
|
|
|
|
|
53
|
|
|
return $retryJob; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* {@inheritdoc} |
|
58
|
|
|
*/ |
|
59
|
|
|
public function createFromSchedule(ScheduleInterface $schedule, $currentTime = 'now'): JobInterface |
|
60
|
|
|
{ |
|
61
|
|
|
/** @var JobInterface $job */ |
|
62
|
|
|
$job = $this->createNew(); |
|
63
|
|
|
$job->setSchedule($schedule); |
|
64
|
|
|
$job->setCommand($schedule->getCommand()); |
|
|
|
|
|
|
65
|
|
|
$job->setArgs($schedule->getArgs()); |
|
66
|
|
|
$job->setExecuteAfter($schedule->getNextRunDate($currentTime)); |
|
67
|
|
|
|
|
68
|
|
|
return $job; |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|