Skip to content

Commit

Permalink
Expose query parameter for Schedule list (#538)
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk authored Dec 17, 2024
1 parent 8059ef7 commit a775cb1
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/Client/ScheduleClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,13 @@ public function getHandle(string $scheduleID, ?string $namespace = null): Schedu
public function listSchedules(
?string $namespace = null,
int $pageSize = 0,
string $query = '',
): Paginator {
// Build request
$request = (new ListSchedulesRequest())
->setNamespace($namespace ?? $this->clientOptions->namespace)
->setMaximumPageSize($pageSize);
->setMaximumPageSize($pageSize)
->setQuery($query);

$loader = function (ListSchedulesRequest $request): \Generator {
do {
Expand Down
3 changes: 2 additions & 1 deletion src/Client/ScheduleClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ public function getHandle(string $scheduleID, ?string $namespace = null): Schedu
*
* @param non-empty-string|null $namespace If null, the preconfigured namespace will be used.
* @param int<0, max> $pageSize Maximum number of Schedule info per page.
* @param string $query Temporal Visibility Query. {@link https://docs.temporal.io/visibility#list-filter}
*
* @return Paginator<ScheduleListEntry>
*/
public function listSchedules(?string $namespace = null, int $pageSize = 0): Paginator;
public function listSchedules(?string $namespace = null, int $pageSize = 0, string $query = ''): Paginator;
}
60 changes: 60 additions & 0 deletions tests/Acceptance/Extra/Schedule/ScheduleClientTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

declare(strict_types=1);

namespace Temporal\Tests\Acceptance\Extra\Update\ScheduleClient;

use PHPUnit\Framework\Attributes\Test;
use Temporal\Client\Schedule\Action\StartWorkflowAction;
use Temporal\Client\Schedule\Schedule;
use Temporal\Client\Schedule\ScheduleHandle;
use Temporal\Client\Schedule\ScheduleOptions;
use Temporal\Client\Schedule\Spec\ScheduleSpec;
use Temporal\Client\Schedule\Spec\ScheduleState;
use Temporal\Client\ScheduleClientInterface;
use Temporal\DataConverter\EncodedCollection;
use Temporal\Tests\Acceptance\App\TestCase;

class ScheduleClientTest extends TestCase
{
#[Test]
public function listSchedulesWithQuery(
ScheduleClientInterface $client,
): void
{
/** @var list<ScheduleHandle> $handle */
$handle = [];
// Create a new schedules
for ($i = 0; $i < 12; $i++) {
$handle[] = $client->createSchedule(
Schedule::new()
->withAction(StartWorkflowAction::new('TestWorkflow'))
->withSpec(ScheduleSpec::new()->withStartTime('+1 hour'))
->withState(ScheduleState::new()->withPaused(true)),
ScheduleOptions::new()
->withSearchAttributes(
EncodedCollection::fromValues([
'bar' => $i % 2 === 0 ? 4242 : 24,
])
)
);
}

try {
$paginator = $client->listSchedules(
pageSize: 5,
query: 'bar = 4242'
);

$this->assertCount(5, $paginator->getPageItems());

$next = $paginator->getNextPage();
$this->assertNotNull($next);
$this->assertCount(1, $next->getPageItems());
} finally {
foreach ($handle as $h) {
$h->delete();
}
}
}
}
2 changes: 1 addition & 1 deletion tests/Acceptance/Extra/Schedule/ScheduleUpdateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Temporal\Tests\Acceptance\Extra\Update\DynamicUpdate;
namespace Temporal\Tests\Acceptance\Extra\Update\ScheduleUpdate;

use PHPUnit\Framework\Attributes\Test;
use Temporal\Client\Schedule\Action\StartWorkflowAction;
Expand Down

0 comments on commit a775cb1

Please sign in to comment.