コード例 #1
0
 public function testFindSchedules()
 {
     /**
      * @var ScheduleManager $scheduleManager
      */
     $scheduleManager = $this->getContainer()->get('abc.job.schedule_manager');
     /**
      * @var JobManagerInterface $jobManager
      */
     $jobManager = $this->getContainer()->get('abc.job.job_manager');
     $schedule1 = $scheduleManager->create();
     $schedule1->setType('cron');
     $schedule1->setExpression('foobar');
     $schedule1->setIsActive(true);
     $job1 = $jobManager->create('foo');
     $job1->setStatus(Status::REQUESTED());
     $job1->addSchedule($schedule1);
     $jobManager->save($job1);
     $schedule2 = $scheduleManager->create();
     $schedule2->setType('cron');
     $schedule2->setExpression('barfoo');
     $schedule2->setIsActive(false);
     $job2 = $jobManager->create('foo');
     $job2->setStatus(Status::REQUESTED());
     $job2->addSchedule($schedule2);
     $jobManager->save($job2);
     $scheduleManager->save($schedule2);
     $schedules = $scheduleManager->findSchedules();
     $this->assertCount(1, $schedules);
     $this->assertEquals($schedule1->getExpression(), $schedules[0]->getExpression());
 }
コード例 #2
0
 public function testJobCanRemoveSchedule()
 {
     // create scheduled job
     $schedule = $this->getScheduleManager()->create('cron', '* * * * *');
     $ticket = $this->getJobManager()->addJob('remove_schedule', null, $schedule);
     $this->assertCount(1, $this->getScheduleManager()->findSchedules());
     $this->assertEquals(Status::REQUESTED(), $this->getJobManager()->get($ticket)->getStatus());
     // process schedules
     $this->runConsole("abc:scheduler:process", array("--iteration" => 1));
     $this->processJobs();
     $this->assertTrue($this->containsMessage('removed schedule', $this->getJobManager()->getLogs($ticket)));
     $this->assertEquals(Status::PROCESSED(), $this->getJobManager()->get($ticket)->getStatus());
     $this->assertEmpty($this->getScheduleManager()->findSchedules());
 }
コード例 #3
0
ファイル: Manager.php プロジェクト: aboutcoders/job-bundle
 /**
  * {@inheritdoc}
  */
 public function add(JobInterface $job)
 {
     if (null != $this->validator) {
         $this->logger->debug('Validate job');
         $errors = $this->validator->validate($job);
         if (count($errors) > 0) {
             $this->logger->debug('Validation failed with errors', ['errors' => $errors]);
             throw new ValidationFailedException($errors);
         }
     }
     if (!$this->jobManager->isManagerOf($job)) {
         $job = $this->helper->copyJob($job, $this->jobManager->create());
     }
     $job->setStatus(Status::REQUESTED());
     $job->setProcessingTime(0);
     $this->jobManager->save($job);
     $this->logger->info(sprintf('Added job %s of type "%s"', $job->getTicket(), $job->getType()), ['parameters' => $job->getParameters(), 'schedules' => $job->getSchedules()]);
     if (!$job->hasSchedules()) {
         $this->publishJob($job);
     }
     return $job;
 }
コード例 #4
0
 public function testDoExitControllerReturnsFalse()
 {
     $this->controller->expects($this->any())->method('doStop')->willReturn(false);
     $this->assertFalse($this->subject->doStop());
     $this->assertEquals(Status::REQUESTED(), $this->job->getStatus());
 }
コード例 #5
0
 public static function provideNonCancelStatus()
 {
     return [[Status::REQUESTED()], [Status::PROCESSING()], [Status::PROCESSED()], [Status::SLEEPING()], [Status::ERROR()]];
 }
コード例 #6
0
 /**
  * @return array
  */
 public static function getNonTerminatedStatus()
 {
     return [[Status::REQUESTED()], [Status::SLEEPING()], [Status::PROCESSING()]];
 }
コード例 #7
0
 /**
  * @return array
  */
 public static function getFindByCountData()
 {
     return [[['type' => 'foo'], 1], [['type' => ['foo', 'bar']], 2], [['type' => 'undefined'], 0], [['type' => 'foo', 'status' => Status::REQUESTED()], 1], [['type' => 'foo', 'status' => Status::PROCESSING()], 0], [['type' => ['$match' => 'foo']], 2]];
 }
コード例 #8
0
 public function testFindByWithStatus()
 {
     $job = $this->subject->create('JobType', null, new Schedule('Type', 'Expression'));
     $job->setStatus(Status::REQUESTED());
     $this->subject->save($job);
     $this->assertCount(1, $this->subject->findBy(['status' => Status::REQUESTED()]));
     $this->assertEmpty($this->subject->findBy(['status' => Status::PROCESSED()]));
 }