1 | <?php |
||
21 | class MessageManager extends BaseEntityManager implements MessageManagerInterface |
||
22 | { |
||
23 | /** |
||
24 | * {@inheritdoc} |
||
25 | */ |
||
26 | public function save($message, $andFlush = true) |
||
35 | |||
36 | /** |
||
37 | * {@inheritdoc} |
||
38 | */ |
||
39 | public function findByTypes(array $types, $state, $batchSize) |
||
40 | { |
||
41 | $params = array(); |
||
42 | $query = $this->prepareStateQuery($state, $types, $batchSize, $params); |
||
43 | |||
44 | $query->setParameters($params); |
||
45 | |||
46 | return $query->getQuery()->execute(); |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * {@inheritdoc} |
||
51 | */ |
||
52 | public function findByAttempts(array $types, $state, $batchSize, $maxAttempts = null, $attemptDelay = 10) |
||
53 | { |
||
54 | $params = array(); |
||
55 | $query = $this->prepareStateQuery($state, $types, $batchSize, $params); |
||
56 | |||
57 | if ($maxAttempts) { |
||
58 | $query |
||
59 | ->andWhere('m.restartCount < :maxAttempts') |
||
60 | ->andWhere('m.updatedAt < :delayDate'); |
||
61 | |||
62 | $params['maxAttempts'] = $maxAttempts; |
||
63 | $now = new \DateTime(); |
||
64 | $params['delayDate'] = $now->add(\DateInterval::createFromDateString(($attemptDelay * -1).' second')); |
||
65 | } |
||
66 | |||
67 | $query->setParameters($params); |
||
68 | |||
69 | return $query->getQuery()->execute(); |
||
70 | } |
||
71 | |||
72 | /** |
||
73 | * {@inheritdoc} |
||
74 | */ |
||
75 | public function countStates() |
||
76 | { |
||
77 | $tableName = $this->getEntityManager()->getClassMetadata($this->class)->table['name']; |
||
78 | |||
79 | $stm = $this->getConnection()->query(sprintf('SELECT state, count(state) as cnt FROM %s GROUP BY state', $tableName)); |
||
80 | |||
81 | $states = array( |
||
82 | MessageInterface::STATE_DONE => 0, |
||
83 | MessageInterface::STATE_ERROR => 0, |
||
84 | MessageInterface::STATE_IN_PROGRESS => 0, |
||
85 | MessageInterface::STATE_OPEN => 0, |
||
86 | ); |
||
87 | |||
88 | foreach ($stm->fetch() as $data) { |
||
89 | $states[$data['state']] = $data['cnt']; |
||
90 | } |
||
91 | |||
92 | return $states; |
||
93 | } |
||
94 | |||
95 | /** |
||
96 | * {@inheritdoc} |
||
97 | */ |
||
98 | public function cleanup($maxAge) |
||
114 | |||
115 | /** |
||
116 | * {@inheritdoc} |
||
117 | */ |
||
118 | public function cancel(MessageInterface $message, $force = false) |
||
119 | { |
||
120 | if (($message->isRunning() || $message->isError()) && !$force) { |
||
121 | return; |
||
122 | } |
||
123 | |||
124 | $message->setState(MessageInterface::STATE_CANCELLED); |
||
125 | |||
126 | $this->save($message); |
||
127 | } |
||
128 | |||
129 | /** |
||
130 | * {@inheritdoc} |
||
131 | */ |
||
132 | public function restart(MessageInterface $message) |
||
133 | { |
||
134 | if ($message->isOpen() || $message->isRunning() || $message->isCancelled()) { |
||
135 | return; |
||
136 | } |
||
137 | |||
138 | $this->cancel($message, true); |
||
139 | |||
140 | $newMessage = clone $message; |
||
141 | $newMessage->setRestartCount($message->getRestartCount() + 1); |
||
142 | $newMessage->setType($message->getType()); |
||
143 | |||
144 | return $newMessage; |
||
145 | } |
||
146 | |||
147 | /** |
||
148 | * {@inheritdoc} |
||
149 | */ |
||
150 | public function getPager(array $criteria, $page, $limit = 10, array $sort = array()) |
||
191 | |||
192 | /** |
||
193 | * @param int $state |
||
194 | * @param array $types |
||
195 | * @param int $batchSize |
||
196 | * @param array $parameters |
||
197 | * |
||
198 | * @return QueryBuilder |
||
199 | */ |
||
200 | protected function prepareStateQuery($state, $types, $batchSize, &$parameters) |
||
230 | } |
||
231 |
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.