mmucklo /
DtcQueueBundle
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace Dtc\QueueBundle\Manager; |
||||
| 4 | |||||
| 5 | use Dtc\QueueBundle\Exception\UnsupportedException; |
||||
| 6 | use Dtc\QueueBundle\Model\Job; |
||||
| 7 | use Dtc\QueueBundle\Model\Run; |
||||
| 8 | use Dtc\QueueBundle\Util\Util; |
||||
| 9 | |||||
| 10 | class RunManager |
||||
| 11 | { |
||||
| 12 | /** @var string */ |
||||
| 13 | protected $runClass; |
||||
| 14 | |||||
| 15 | 41 | public function __construct($runClass) |
|||
| 16 | { |
||||
| 17 | 41 | $this->runClass = $runClass; |
|||
| 18 | 41 | } |
|||
| 19 | |||||
| 20 | /** |
||||
| 21 | * @return string |
||||
| 22 | */ |
||||
| 23 | 22 | public function getRunClass() |
|||
| 24 | { |
||||
| 25 | 22 | return $this->runClass; |
|||
| 26 | } |
||||
| 27 | |||||
| 28 | /** |
||||
| 29 | * @param string $runClass |
||||
| 30 | */ |
||||
| 31 | 1 | public function setRunClass($runClass) |
|||
| 32 | { |
||||
| 33 | 1 | $this->runClass = $runClass; |
|||
| 34 | 1 | } |
|||
| 35 | |||||
| 36 | /** |
||||
| 37 | * @return int Number of archived runs pruned |
||||
| 38 | * |
||||
| 39 | * @throws UnsupportedException |
||||
| 40 | */ |
||||
| 41 | 1 | public function pruneArchivedRuns(\DateTime $olderThan) |
|||
| 42 | { |
||||
| 43 | 1 | throw new UnsupportedException('not supported - '.$olderThan->getTimestamp()); |
|||
| 44 | } |
||||
| 45 | |||||
| 46 | /** |
||||
| 47 | * Prunes stalled runs. |
||||
| 48 | * |
||||
| 49 | * @return int Number of stalled runs pruned |
||||
| 50 | * |
||||
| 51 | * @throws UnsupportedException |
||||
| 52 | */ |
||||
| 53 | 1 | public function pruneStalledRuns() |
|||
| 54 | { |
||||
| 55 | 1 | throw new UnsupportedException('not supported'); |
|||
| 56 | } |
||||
| 57 | |||||
| 58 | /** |
||||
| 59 | * @param float $start |
||||
| 60 | */ |
||||
| 61 | 3 | public function recordHeartbeat(Run $run, $start, Job $job = null) |
|||
| 62 | { |
||||
| 63 | 3 | $jobId = null; |
|||
| 64 | 3 | if (null !== $job) { |
|||
| 65 | 3 | $jobId = $job->getId(); |
|||
| 66 | } |
||||
| 67 | |||||
| 68 | 3 | $heartbeat = microtime(true); |
|||
| 69 | 3 | $run->setLastHeartbeatAt(Util::getMicrotimeFloatDateTime($heartbeat)); |
|||
| 70 | 3 | $run->setCurrentJobId($jobId); |
|||
| 71 | 3 | $run->setElapsed($heartbeat - $start); |
|||
| 72 | 3 | $this->persistRun($run); |
|||
| 73 | 3 | } |
|||
| 74 | |||||
| 75 | /** |
||||
| 76 | * @param string $action |
||||
| 77 | */ |
||||
| 78 | 5 | protected function persistRun(Run $run, $action = 'persist') |
|||
|
0 ignored issues
–
show
The parameter
$run is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. Loading history...
|
|||||
| 79 | { |
||||
| 80 | // To be overridden |
||||
| 81 | 5 | } |
|||
| 82 | |||||
| 83 | /** |
||||
| 84 | * @param int $count |
||||
| 85 | */ |
||||
| 86 | 3 | public function updateProcessed(Run $run, $count) |
|||
| 87 | { |
||||
| 88 | 3 | $run->setProcessed($count); |
|||
| 89 | 3 | $this->persistRun($run); |
|||
| 90 | 3 | } |
|||
| 91 | |||||
| 92 | /** |
||||
| 93 | * Sets up the runManager (document / entity persister) if appropriate. |
||||
| 94 | * |
||||
| 95 | * @param float $start |
||||
| 96 | * @param int|null $maxCount |
||||
| 97 | * @param int|null $duration |
||||
| 98 | * @param int $processTimeout |
||||
| 99 | * |
||||
| 100 | * @return Run |
||||
| 101 | */ |
||||
| 102 | 5 | public function runStart($start, $maxCount = null, $duration = null, $processTimeout = null) |
|||
| 103 | { |
||||
| 104 | 5 | $runClass = $this->getRunClass(); |
|||
| 105 | /** @var Run $run */ |
||||
| 106 | 5 | $run = new $runClass(); |
|||
| 107 | 5 | $startDate = Util::getMicrotimeFloatDateTime($start); |
|||
| 108 | 5 | $run->setLastHeartbeatAt($startDate); |
|||
| 109 | 5 | $run->setStartedAt($startDate); |
|||
| 110 | 5 | if (null !== $maxCount) { |
|||
| 111 | 3 | $run->setMaxCount($maxCount); |
|||
| 112 | } |
||||
| 113 | 5 | if (null !== $duration) { |
|||
| 114 | 2 | $run->setDuration($duration); |
|||
| 115 | } |
||||
| 116 | 5 | $run->setHostname(gethostname()); |
|||
| 117 | 5 | $run->setPid(getmypid()); |
|||
| 118 | 5 | $run->setProcessed(0); |
|||
| 119 | 5 | $run->setProcessTimeout($processTimeout); |
|||
| 120 | 5 | $this->persistRun($run); |
|||
| 121 | |||||
| 122 | 5 | return $run; |
|||
| 123 | } |
||||
| 124 | |||||
| 125 | /** |
||||
| 126 | * @param int|null $start |
||||
| 127 | */ |
||||
| 128 | 5 | public function runStop(Run $run, $start) |
|||
| 129 | { |
||||
| 130 | 5 | $end = microtime(true); |
|||
| 131 | 5 | $run->setEndedAt(Util::getMicrotimeFloatDateTime($end)); |
|||
| 132 | 5 | $run->setElapsed($end - $start); |
|||
| 133 | 5 | $this->persistRun($run, 'remove'); |
|||
| 134 | 5 | } |
|||
| 135 | } |
||||
| 136 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.