Skip to content

Commit

Permalink
Support query for listing schedules (#310)
Browse files Browse the repository at this point in the history
Fixes #300
  • Loading branch information
cretz authored Jul 19, 2024
1 parent 23af803 commit 32d1931
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/Temporalio/Client/Schedules/ScheduleListOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ namespace Temporalio.Client.Schedules
/// </summary>
public class ScheduleListOptions : ICloneable
{
/// <summary>
/// Gets or sets the visibility list filter.
/// </summary>
public string? Query { get; set; }

/// <summary>
/// Gets or sets RPC options for listing schedules.
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions src/Temporalio/Client/TemporalClient.Schedules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ private async IAsyncEnumerable<ScheduleListDescription> ListSchedulesInternalAsy
{
// TODO(cretz): Allow setting of page size or next page token?
Namespace = Client.Options.Namespace,
Query = input.Options?.Query ?? string.Empty,
};
do
{
Expand Down
24 changes: 21 additions & 3 deletions tests/Temporalio.Tests/Client/TemporalClientScheduleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ namespace Temporalio.Tests.Client;
using System.Collections.Generic;
using Temporalio.Api.Enums.V1;
using Temporalio.Client.Schedules;
using Temporalio.Common;
using Temporalio.Converters;
using Temporalio.Exceptions;
using Xunit;
Expand Down Expand Up @@ -181,14 +182,21 @@ await AssertMore.EqualEventuallyAsync(1, async () =>
"some result",
await Client.GetWorkflowHandle(exec.WorkflowId, exec.FirstExecutionRunId).GetResultAsync<string>());

// Create 4 more schedules of the same type and confirm they are in the list eventually
// Create 4 more schedules of the same type and confirm they are in the list eventually.
// But create two with different search attributes.
await EnsureSearchAttributesPresentAsync();
var optsWithAttrs = new ScheduleOptions()
{
TypedSearchAttributes = new SearchAttributeCollection.Builder().
Set(AttrKeyword, "SomeKeyword").ToSearchAttributeCollection(),
};
var expectedIds = new List<string>
{
handle.Id,
(await Client.CreateScheduleAsync($"{handle.Id}-1", newSched)).Id,
(await Client.CreateScheduleAsync($"{handle.Id}-2", newSched)).Id,
(await Client.CreateScheduleAsync($"{handle.Id}-3", newSched)).Id,
(await Client.CreateScheduleAsync($"{handle.Id}-4", newSched)).Id,
(await Client.CreateScheduleAsync($"{handle.Id}-3", newSched, optsWithAttrs)).Id,
(await Client.CreateScheduleAsync($"{handle.Id}-4", newSched, optsWithAttrs)).Id,
};
await AssertMore.EqualEventuallyAsync(expectedIds, async () =>
{
Expand All @@ -201,6 +209,16 @@ await AssertMore.EqualEventuallyAsync(expectedIds, async () =>
return actualIds;
});

// Confirm list with query works
var actualIds = new List<string>();
await foreach (var sched in Client.ListSchedulesAsync(
new() { Query = $"{AttrKeyword.Name} = 'SomeKeyword'" }))
{
actualIds.Add(sched.Id);
}
actualIds.Sort();
Assert.Equal(new List<string> { $"{handle.Id}-3", $"{handle.Id}-4" }, actualIds);

// Delete when done
await TestUtils.DeleteAllSchedulesAsync(Client);
}
Expand Down

0 comments on commit 32d1931

Please sign in to comment.