Skip to content

Commit 6cc30c0

Browse files
authored
Merge pull request #14 from Flowpack/ah/add-option-for-partition-queues
TASK: optional supply of queuePartition when scheduling a pipeline
2 parents e20aff3 + 1b772ad commit 6cc30c0

2 files changed

Lines changed: 42 additions & 4 deletions

File tree

Classes/PrunnerApiService.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Flowpack\Prunner\Dto\PipelinesAndJobsResponse;
99
use Flowpack\Prunner\ValueObject\JobId;
1010
use Flowpack\Prunner\ValueObject\PipelineName;
11+
use Flowpack\Prunner\ValueObject\QueuePartitionName;
1112
use GuzzleHttp\Client;
1213
use GuzzleHttp\Exception\GuzzleException;
1314
use Neos\Flow\Annotations as Flow;
@@ -91,14 +92,21 @@ public function loadJobLogs(JobId $jobId, string $taskName): JobLogs
9192
}
9293

9394
/**
95+
* @param QueuePartitionName|null $queuePartition only needed for queue_strategy "partitioned_replace"
9496
* @throws \JsonException
9597
*/
96-
public function schedulePipeline(PipelineName $pipeline, array $variables): JobId
98+
public function schedulePipeline(PipelineName $pipeline, array $variables, ?QueuePartitionName $queuePartition = null): JobId
9799
{
98-
$response = $this->apiCall('POST', 'pipelines/schedule', json_encode([
100+
$requestBody = [
99101
'pipeline' => $pipeline->getName(),
100-
'variables' => $variables
101-
], JSON_THROW_ON_ERROR | JSON_FORCE_OBJECT));
102+
'variables' => $variables,
103+
];
104+
105+
if ($queuePartition !== null) {
106+
$requestBody['queuePartition'] = $queuePartition->getName();
107+
}
108+
109+
$response = $this->apiCall('POST', 'pipelines/schedule', json_encode($requestBody, JSON_THROW_ON_ERROR | JSON_FORCE_OBJECT));
102110
if ($response->getStatusCode() !== 202) {
103111
throw new \RuntimeException('Scheduling a new pipeline run should have returned status code 202, but got: ' . $response->getStatusCode());
104112
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Flowpack\Prunner\ValueObject;
6+
7+
use Neos\Flow\Annotations as Flow;
8+
9+
/**
10+
* @Flow\Proxy(false)
11+
*/
12+
class QueuePartitionName
13+
{
14+
private string $name;
15+
16+
private function __construct(string $name)
17+
{
18+
$this->name = $name;
19+
}
20+
21+
public static function create(string $name)
22+
{
23+
return new self($name);
24+
}
25+
26+
public function getName(): string
27+
{
28+
return $this->name;
29+
}
30+
}

0 commit comments

Comments
 (0)