Beispiel #1
0
 public function dataProviderMatchFilter()
 {
     $args = array('baz' => 'test');
     $job = new Job('FooJob', $args);
     $jobId = $job->getId();
     return array(array($job, false, null), array($job, false, array()), array($job, true, array('id' => $jobId)), array($job, false, array('id' => 'some-other-id')), array($job, false, array('id' => $jobId, 'class' => 'FuzzJob')), array($job, false, array('class' => 'FuzzJob')), array($job, true, array('id' => $jobId, 'class' => 'FooJob')), array($job, true, array('class' => 'FooJob')), array($job, false, array('id' => '123', 'class' => 'FooJob')));
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $output = new SymfonyStyle($input, $output);
     $job = new Job($input->getArgument('target'));
     // @todo remove new Job. @todo arguments
     if ($input->isInteractive()) {
         if (!$output->confirm(sprintf('you sure?', $job->getJobClass()), false)) {
             return;
         }
     }
     if (true === ($result = $this->jobPerformer->perform($job))) {
         $output->success('Job "' . $job->getJobClass() . '" with arguments (?) successfully performed');
     } else {
         throw $result;
     }
 }
 /**
  * {@inheritDoc}
  */
 public function remove(QueueInterface $queue, $filter = array())
 {
     $jobsRemoved = 0;
     $queueKey = $this->getRedisKey($queue);
     $tmpKey = $queueKey . ':removal:' . time() . ':' . uniqid();
     $enqueueKey = $tmpKey . ':enqueue';
     // Move each job from original queue to a temporary list and leave
     while (\true) {
         $payload = $this->redis->rpoplpush($queueKey, $tmpKey);
         if (!empty($payload)) {
             $job = Job::decode($payload);
             // @todo should be something like $this->jobEncoderThingy->decode()
             if ($job instanceof FilterableJobInterface && $job::matchFilter($job, $filter)) {
                 $this->redis->rpop($tmpKey);
                 $jobsRemoved++;
             } else {
                 $this->redis->rpoplpush($tmpKey, $enqueueKey);
             }
         } else {
             break;
         }
     }
     // Move back from enqueue list to original queue
     while (\true) {
         $payload = $this->redis->rpoplpush($enqueueKey, $queueKey);
         if (empty($payload)) {
             break;
         }
     }
     $this->redis->del($tmpKey);
     $this->redis->del($enqueueKey);
     return $jobsRemoved;
 }
Beispiel #4
0
 public function testBeforePerformEventCanStopWork()
 {
     $eventDispatcher = new EventDispatcher();
     $this->worker = new Worker($this->getMock('Resque\\Component\\Job\\Factory\\JobInstanceFactoryInterface'), $eventDispatcher);
     $eventDispatcher->addListener('resque.job.before_perform', function () {
         throw new \Exception('Take a break');
     });
     $eventTriggered = 0;
     $eventDispatcher->addListener(ResqueJobEvents::FAILED, function () use(&$eventTriggered) {
         $eventTriggered++;
     });
     return $this->markTestIncomplete();
     $job = new Job('Resque\\Component\\Job\\Tests\\Jobs\\Simple');
     $queue = new RedisQueue($this->redis);
     $queue->setName('baz');
     $job->setOriginQueue($queue);
     $this->assertFalse($this->worker->perform($job), 'Job was still performed even though "resque.job.before_perform" throw an exception');
     $this->assertEquals(1, $eventTriggered, 'Expected event "resque.job.failed" was triggered for thrown exception on "resque.job.before_perform"');
 }