/**
  * @return JobInterface
  */
 public function build()
 {
     $job = new Job();
     $job->setType($this->type);
     $job->setParameters($this->parameters);
     foreach ($this->schedules as $schedule) {
         $job->addSchedule(new Schedule($schedule[0], $schedule[1]));
     }
     return $job;
 }
 public function testAppliesConstraintsOfConstraintProviders()
 {
     $job = new Job();
     $job->setType('abc.sleeper');
     $job->setParameters(['foobar']);
     $errors = $this->validator->validate($job);
     $this->assertTrue($errors->has(0));
     $this->assertEquals('parameters[0]', $errors->get(0)->getPropertyPath());
     $this->assertEquals('This value should be a valid number.', $errors->get(0)->getMessage());
 }
 public function testValidateWithType()
 {
     $job = new Job();
     $job->setType('foobar');
     $job->setParameters(['JobParameters']);
     $validator = $this->createMock(ValidatorInterface::class);
     $contextualValidator = $this->createMock(ContextualValidatorInterface::class);
     $this->context->expects($this->once())->method('getValidator')->willReturn($validator);
     $validator->expects($this->once())->method('inContext')->with($this->context)->willReturn($contextualValidator);
     $contextualValidator->expects($this->once())->method('atPath')->with('parameters')->willReturn($contextualValidator);
     $contextualValidator->expects($this->once())->method('validate')->with(['JobParameters'], new Parameters(['type' => $job->getType()]));
     $this->subject->validate($job, new JobConstraint());
 }
 /**
  * @return Job
  */
 public static function createJob($ticket = null, $type = null, $status = null, $processingTime = null, $parameters = null, array $schedules = array())
 {
     $job = new Job();
     $job->setTicket($ticket);
     $job->setType($type);
     $job->setParameters($parameters);
     $job->setProcessingTime($processingTime);
     foreach ($schedules as $schedule) {
         $job->addSchedule($schedule);
     }
     if ($status != null) {
         $job->setStatus($status);
     }
     return $job;
 }
 public function testOnSchedule()
 {
     $job = new Job();
     $job->setType('type');
     $job->setTicket('ticket');
     $schedule = new Schedule();
     $schedule->setJob($job);
     $event = new SchedulerEvent($schedule);
     $self = $this;
     $this->producer->expects($this->once())->method('produce')->willReturnCallback(function (Message $message) use($self) {
         $this->assertEquals('ticket', $message->getTicket());
         $this->assertEquals('type', $message->getType());
     });
     $this->subject->onSchedule($event);
 }
 public function testCreatesLoggerWithAddedHandlers()
 {
     $job = new Job();
     $job->setType('JobType');
     $handler = $this->createMock(HandlerInterface::class);
     $extraHandler = $this->createMock(HandlerInterface::class);
     $factory = $this->getMockBuilder(BaseHandlerFactory::class)->disableOriginalConstructor()->getMock();
     $jobType = $this->createMock(JobTypeInterface::class);
     $this->handlerFactory->register($factory);
     $jobType->expects($this->any())->method('getLogLevel')->willReturn(Logger::CRITICAL);
     $this->registry->expects($this->once())->method('get')->with($job->getType())->willReturn($jobType);
     $factory->expects($this->once())->method('createHandler')->willReturn($handler);
     $this->subject->addHandler($extraHandler);
     $logger = $this->subject->create($job);
     $this->assertContains($handler, $logger->getHandlers());
     $this->assertContains($extraHandler, $logger->getHandlers());
 }
 /**
  * Resolves the parameters of a job.
  *
  * @param string $type       The job type
  * @param array  $parameters The job parameters
  * @return array The parameters the job can be invoked with
  */
 public function resolveParameters($type, array $parameters)
 {
     // serialize/deserialize parameters
     $deserializedParameters = $parameters;
     if (count($parameters) > 0) {
         $data = static::getSerializationHelper()->serializeParameters($type, $parameters);
         /**
          * @var array $deserializedParameters
          */
         $deserializedParameters = static::getSerializationHelper()->deserializeParameters($type, $data);
     }
     // Dispatch event to let listeners register runtime parameters
     $job = new Job();
     $job->setType($type);
     $job->setParameters($deserializedParameters);
     $event = new ExecutionEvent($job, new Context());
     static::getDispatcher()->dispatch(JobEvents::JOB_PRE_EXECUTE, $event);
     return Invoker::resolveParameters(static::getJobType($type), $event->getContext(), $deserializedParameters);
 }
 public function testDeleteLogWithNonExistingFile()
 {
     $job = new Job();
     $job->setTicket('job-ticket');
     $job->setType('job-type');
     $this->subject->deleteByJob($job);
 }
 /**
  * @param string             $type
  * @param Status             $status
  * @param array              $parameters
  * @param SchedulerInterface $schedule
  * @param mixed              $response
  * @return Job
  */
 public function createJob($type, $status = null, $parameters = null, $schedule = null, $response = null)
 {
     $job = new Job();
     $job->setType($type);
     $job->setParameters($parameters);
     $job->setResponse('JobResponse');
     if ($status != null) {
         $job->setStatus($status);
     }
     if ($schedule !== null) {
         $job->addSchedule($schedule);
     }
     return $job;
 }
 /**
  * @param array $parameters
  * @return Job
  */
 private function buildJobFromArray($parameters)
 {
     $job = new Job();
     $job->setType(isset($parameters['type']) ? $parameters['type'] : null);
     if (isset($parameters['parameters']) && count($parameters['parameters']) > 0) {
         $message = new Message($parameters['parameters'][0]['to'], $parameters['parameters'][0]['from'], $parameters['parameters'][0]['subject'], $parameters['parameters'][0]['message']);
         $job->setParameters([$message]);
     }
     if (isset($parameters['schedules'])) {
         foreach ($parameters['schedules'] as $scheduleParameters) {
             $schedule = new Schedule($scheduleParameters['type'], $scheduleParameters['expression']);
             $job->addSchedule($schedule);
         }
     }
     return $job;
 }
 /**
  * @param Status $status
  * @dataProvider provideStatusToSkip
  */
 public function testOnMessageSkipsExecutionIfStatusIs(Status $status)
 {
     $message = new Message('job-type', 'job-ticket');
     $job = new Job();
     $job->setType($message->getType());
     $job->setTicket($message->getTicket());
     $job->setStatus($status);
     $this->jobManager->expects($this->any())->method('findByTicket')->willReturn($job);
     $this->dispatcher->expects($this->never())->method('dispatch');
     $this->locker->expects($this->never())->method('lock');
     $this->subject->onMessage($message);
 }