You are here

public function Job::__construct in Advanced Queue 8

Constructs a new Job object.

Parameters

array $definition: The job definition.

File

src/Job.php, line 96

Class

Job
Represents a job.

Namespace

Drupal\advancedqueue

Code

public function __construct(array $definition) {
  foreach ([
    'type',
    'payload',
    'state',
  ] as $required_property) {
    if (empty($definition[$required_property])) {
      throw new \InvalidArgumentException(sprintf('Missing property "%s"', $required_property));
    }
  }
  $this
    ->assertState($definition['state']);
  $this->id = !empty($definition['id']) ? $definition['id'] : '';
  $this->queueId = !empty($definition['queue_id']) ? $definition['queue_id'] : '';
  $this->type = $definition['type'];
  $this->payload = $definition['payload'];
  $this->state = $definition['state'];
  $this->message = !empty($definition['message']) ? $definition['message'] : NULL;
  $this->numRetries = !empty($definition['num_retries']) ? $definition['num_retries'] : 0;
  $this->available = !empty($definition['available']) ? (int) $definition['available'] : 0;
  $this->processed = !empty($definition['processed']) ? (int) $definition['processed'] : 0;
  $this->expires = !empty($definition['expires']) ? (int) $definition['expires'] : 0;
}