sfcod /
jobqueue
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | namespace SfCod\QueueBundle\Command; |
||
| 4 | |||
| 5 | use Illuminate\Queue\Jobs\Job; |
||
| 6 | use SfCod\QueueBundle\Failer\MongoFailedJobProvider; |
||
| 7 | use SfCod\QueueBundle\Service\JobQueue; |
||
| 8 | use SfCod\QueueBundle\Service\MongoDriverInterface; |
||
| 9 | use Symfony\Component\Console\Command\Command; |
||
| 10 | use Symfony\Component\Console\Input\InputInterface; |
||
| 11 | use Symfony\Component\Console\Input\InputOption; |
||
| 12 | use Symfony\Component\Console\Output\OutputInterface; |
||
| 13 | use Symfony\Component\Console\Style\SymfonyStyle; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * Class ReleaseFailedCommand |
||
| 17 | * |
||
| 18 | * @author Virchenko Maksim <[email protected]> |
||
| 19 | * |
||
| 20 | * @package SfCod\QueueBundle\Command |
||
| 21 | */ |
||
| 22 | class RetryCommand extends Command |
||
| 23 | { |
||
| 24 | /** |
||
| 25 | * @var JobQueue |
||
| 26 | */ |
||
| 27 | protected $queue; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @var MongoFailedJobProvider |
||
| 31 | */ |
||
| 32 | protected $failer; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * RetryCommand constructor. |
||
| 36 | * |
||
| 37 | * @param JobQueue $queue |
||
| 38 | * @param MongoDriverInterface $mongoDriver |
||
|
0 ignored issues
–
show
|
|||
| 39 | */ |
||
| 40 | public function __construct(JobQueue $queue, MongoFailedJobProvider $failer) |
||
| 41 | { |
||
| 42 | $this->queue = $queue; |
||
| 43 | $this->failer = $failer; |
||
| 44 | |||
| 45 | parent::__construct(); |
||
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Configure command |
||
| 50 | */ |
||
| 51 | protected function configure() |
||
| 52 | { |
||
| 53 | $this->setName('job-queue:retry') |
||
| 54 | ->setDescription('Release all failed jobs.') |
||
| 55 | ->addOption('id', null, InputOption::VALUE_OPTIONAL, 'Job id to retry', null); |
||
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Execute command |
||
| 60 | * |
||
| 61 | * @param InputInterface $input |
||
| 62 | * @param OutputInterface $output |
||
| 63 | * |
||
| 64 | * @return int|null|void |
||
| 65 | */ |
||
| 66 | public function execute(InputInterface $input, OutputInterface $output) |
||
| 67 | { |
||
| 68 | $io = new SymfonyStyle($input, $output); |
||
| 69 | |||
| 70 | $jobsCount = 0; |
||
| 71 | if (is_null($input->getOption('id'))) { |
||
| 72 | foreach ($this->failer->all() as $job) { |
||
| 73 | if ($this->retryJob($job)) { |
||
| 74 | ++$jobsCount; |
||
| 75 | } |
||
| 76 | } |
||
| 77 | } else { |
||
| 78 | $job = $this->failer->find($input->getOption('id')); |
||
| 79 | $this->retryJob($job); |
||
|
0 ignored issues
–
show
$job is of type array, but the function expects a object<Illuminate\Queue\Jobs\Job>.
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
| 80 | |||
| 81 | ++$jobsCount; |
||
| 82 | } |
||
| 83 | |||
| 84 | $io->success(sprintf("[%d] job(s) has been released.\n", $jobsCount)); |
||
| 85 | } |
||
| 86 | |||
| 87 | /** |
||
| 88 | * Retry job |
||
| 89 | * |
||
| 90 | * @param Job $job |
||
| 91 | * |
||
| 92 | * @return bool |
||
| 93 | */ |
||
| 94 | protected function retryJob($job): bool |
||
| 95 | { |
||
| 96 | $payload = json_decode($job->payload, true); |
||
|
0 ignored issues
–
show
The property
payload does not seem to exist in Illuminate\Queue\Jobs\Job.
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name. If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading. Loading history...
|
|||
| 97 | |||
| 98 | if ($payload && isset($payload['job'], $payload['data'])) { |
||
| 99 | $this->queue->push($payload['job'], $payload['data']); |
||
| 100 | $this->failer->forget($job->_id); |
||
|
0 ignored issues
–
show
The property
_id does not seem to exist in Illuminate\Queue\Jobs\Job.
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name. If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading. Loading history...
|
|||
| 101 | |||
| 102 | return true; |
||
| 103 | } |
||
| 104 | |||
| 105 | return false; |
||
| 106 | } |
||
| 107 | } |
||
| 108 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.