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()); }
/** * @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 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 array|null * @throws \Exception If deserialization fails */ public function getParameters() { if ($this->paramDeserializationError) { return null; } if (is_null(parent::getParameters()) && !is_null($this->serializedParameters)) { try { parent::setParameters(static::getSerializationHelper()->deserializeParameters($this->getType(), $this->serializedParameters)); } catch (\Exception $e) { $this->paramDeserializationError = true; throw $e; } } return parent::getParameters(); }
/** * @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; }
/** * 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); }
/** * @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; }
public function testOnMessageInvokesJob() { $type = 'JobType'; $ticket = 'JobTicket'; $microTime = microtime(true); $parameters = ['parameters']; $response = 'response'; $job = new Job($type); $job->setTicket($ticket); $job->setParameters($parameters); $message = new Message($type, $ticket); $this->jobManager->expects($this->once())->method('findByTicket')->with($message->getTicket())->willReturn($job); $this->locker->expects($this->once())->method('lock')->with(Manager::JOB_LOCK_PREFIX . $job->getTicket()); $this->invoker->expects($this->once())->method('invoke')->with($job, $this->isInstanceOf(Context::class))->willReturn($response); $this->expectsCallsUpdateJob($job, Status::PROCESSED(), 0, $response); $this->jobManager->expects($this->at(2))->method('save')->with($this->callback(function (JobInterface $job) { return $job->getStatus() == Status::PROCESSED(); })); $this->subject->onMessage($message); }