1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of php-task library. |
5
|
|
|
* |
6
|
|
|
* (c) php-task |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the MIT license that is bundled |
9
|
|
|
* with this source code in the file LICENSE. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Task\TaskBundle\Entity; |
13
|
|
|
|
14
|
|
|
use Doctrine\ORM\EntityRepository; |
15
|
|
|
use Doctrine\ORM\NoResultException; |
16
|
|
|
use Task\Execution\TaskExecutionInterface; |
17
|
|
|
use Task\Storage\TaskExecutionRepositoryInterface; |
18
|
|
|
use Task\TaskInterface; |
19
|
|
|
use Task\TaskStatus; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Repository for task-execution. |
23
|
|
|
*/ |
24
|
|
|
class TaskExecutionRepository extends EntityRepository implements TaskExecutionRepositoryInterface |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* {@inheritdoc} |
28
|
|
|
*/ |
29
|
|
|
public function create(TaskInterface $task, \DateTime $scheduleTime) |
30
|
|
|
{ |
31
|
|
|
return new TaskExecution($task, $task->getHandlerClass(), $scheduleTime, $task->getWorkload()); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* {@inheritdoc} |
36
|
|
|
*/ |
37
|
|
|
public function persist(TaskExecutionInterface $execution) |
38
|
|
|
{ |
39
|
|
|
$this->_em->persist($execution); |
40
|
|
|
|
41
|
|
|
return $this; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* {@inheritdoc} |
46
|
|
|
*/ |
47
|
|
|
public function flush() |
48
|
|
|
{ |
49
|
|
|
$this->_em->flush(); |
50
|
|
|
|
51
|
|
|
return $this; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* {@inheritdoc} |
56
|
|
|
*/ |
57
|
|
|
public function findByStartTime(TaskInterface $task, \DateTime $scheduleTime) |
58
|
|
|
{ |
59
|
|
|
try { |
60
|
|
|
return $this->createQueryBuilder('e') |
61
|
|
|
->innerJoin('e.task', 't') |
62
|
|
|
->where('t.uuid = :uuid') |
63
|
|
|
->andWhere('e.scheduleTime = :scheduleTime') |
64
|
|
|
->setParameter('uuid', $task->getUuid()) |
65
|
|
|
->setParameter('scheduleTime', $scheduleTime) |
66
|
|
|
->getQuery() |
67
|
|
|
->getSingleResult(); |
68
|
|
|
} catch (NoResultException $e) { |
69
|
|
|
return; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* {@inheritdoc} |
75
|
|
|
*/ |
76
|
|
|
public function findScheduled(\DateTime $dateTime = null) |
77
|
|
|
{ |
78
|
|
|
if ($dateTime === null) { |
79
|
|
|
$dateTime = new \DateTime(); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
return $this->createQueryBuilder('e') |
83
|
|
|
->innerJoin('e.task', 't') |
84
|
|
|
->where('e.status = :status AND e.scheduleTime < :dateTime') |
85
|
|
|
->setParameter('status', TaskStatus::PLANNED) |
86
|
|
|
->setParameter('dateTime', $dateTime) |
87
|
|
|
->getQuery() |
88
|
|
|
->getResult(); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|