Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions src/Models/Job.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@ class Job
public const STATUS_PROCESSING = 'processing';
public const STATUS_ERROR = 'error';
public const STATUS_FINISHED = 'finished';
public const ATTR_TAG_KEY = 'tag';

/**
* @var string
*/
protected $id;

/**
* @var string|null
* @var array
*/
protected $tag;
protected $attributes = array();

/**
* @var \DateTimeImmutable
Expand Down Expand Up @@ -65,7 +66,27 @@ public function getId(): string
*/
public function getTag(): ?string
{
return $this->tag;
return null !== ($tag = $this->attributes[self::ATTR_TAG_KEY]) ? $tag : null;
}

/**
* @return array
*/
public function getAttributes(): ?array
{
return $this->attributes;
}

/**
* @param string $key
* @param string|null $value
*
* @return Job
*/
public function setAttribute(string $key, ?string $value): Job
{
$this->attributes[$key] = $value;
return $this;
}

/**
Expand All @@ -75,7 +96,7 @@ public function getTag(): ?string
*/
public function setTag(?string $tag): Job
{
$this->tag = $tag;
$this->attributes[self::ATTR_TAG_KEY] = $tag;
return $this;
}

Expand Down
9 changes: 5 additions & 4 deletions src/Resources/JobsResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ public function create(Job $job): Job
$task->getPayload() ?? []
);
}
$response = $this->httpTransport->post($this->httpTransport->getBaseUri() . '/jobs', [
'tasks' => $tasks,
'tag' => $job->getTag()
]);
$response = $this->httpTransport->post($this->httpTransport->getBaseUri() . '/jobs', array_merge(
['tasks' => $tasks],
$job->getAttributes()
)
);
return $this->hydrator->hydrateObjectByResponse($job, $response);
}

Expand Down