Skip to content

Commit 7d76f8c

Browse files
committed
rename schedulehandle and ch to abstract
1 parent 7b41375 commit 7d76f8c

File tree

7 files changed

+101
-85
lines changed

7 files changed

+101
-85
lines changed

samples/ScheduleConsoleApp/ScheduleOperations.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ async Task DeleteExistingSchedulesAsync()
3434
// Delete each existing schedule
3535
await foreach (ScheduleDescription schedule in schedules)
3636
{
37-
IScheduleHandle handle = this.scheduledTaskClient.GetScheduleHandle(schedule.ScheduleId);
37+
ScheduleClient handle = this.scheduledTaskClient.GetDefaultScheduleClient(schedule.ScheduleId);
3838
await handle.DeleteAsync();
3939
Console.WriteLine($"Deleted schedule {schedule.ScheduleId}");
4040
}
@@ -53,28 +53,28 @@ async Task CreateAndManageScheduleAsync()
5353
};
5454

5555
// Create the schedule and get a handle to it
56-
IScheduleHandle scheduleHandle = await this.scheduledTaskClient.CreateScheduleAsync(scheduleOptions);
56+
ScheduleClient DefaultScheduleClient = await this.scheduledTaskClient.CreateScheduleAsync(scheduleOptions);
5757

5858
// Get and print the initial schedule description
59-
await PrintScheduleDescriptionAsync(scheduleHandle);
59+
await PrintScheduleDescriptionAsync(DefaultScheduleClient);
6060

6161
// Pause the schedule
6262
Console.WriteLine("\nPausing schedule...");
63-
await scheduleHandle.PauseAsync();
64-
await PrintScheduleDescriptionAsync(scheduleHandle);
63+
await DefaultScheduleClient.PauseAsync();
64+
await PrintScheduleDescriptionAsync(DefaultScheduleClient);
6565

6666
// Resume the schedule
6767
Console.WriteLine("\nResuming schedule...");
68-
await scheduleHandle.ResumeAsync();
69-
await PrintScheduleDescriptionAsync(scheduleHandle);
68+
await DefaultScheduleClient.ResumeAsync();
69+
await PrintScheduleDescriptionAsync(DefaultScheduleClient);
7070

7171
// Wait for a while to let the schedule run
7272
await Task.Delay(TimeSpan.FromMinutes(30));
7373
}
7474

75-
static async Task PrintScheduleDescriptionAsync(IScheduleHandle scheduleHandle)
75+
static async Task PrintScheduleDescriptionAsync(ScheduleClient DefaultScheduleClient)
7676
{
77-
ScheduleDescription scheduleDescription = await scheduleHandle.DescribeAsync();
77+
ScheduleDescription scheduleDescription = await DefaultScheduleClient.DescribeAsync();
7878
Console.WriteLine(scheduleDescription);
7979
Console.WriteLine("\n\n");
8080
}

samples/ScheduleWebApp/ScheduleController.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public async Task<ActionResult<ScheduleDescription>> CreateSchedule([FromBody] C
5656
StartImmediatelyIfLate = true
5757
};
5858

59-
IScheduleHandle handle = await this.scheduledTaskClient.CreateScheduleAsync(creationOptions);
59+
ScheduleClient handle = await this.scheduledTaskClient.CreateScheduleAsync(creationOptions);
6060
ScheduleDescription description = await handle.DescribeAsync();
6161

6262
this.logger.LogInformation("Created new schedule with ID: {ScheduleId}", createScheduleRequest.Id);
@@ -154,7 +154,7 @@ public async Task<ActionResult<ScheduleDescription>> UpdateSchedule(string id, [
154154

155155
try
156156
{
157-
IScheduleHandle handle = this.scheduledTaskClient.GetScheduleHandle(id);
157+
ScheduleClient handle = this.scheduledTaskClient.GetDefaultScheduleClient(id);
158158

159159
ScheduleUpdateOptions updateOptions = new ScheduleUpdateOptions
160160
{
@@ -194,7 +194,7 @@ public async Task<IActionResult> DeleteSchedule(string id)
194194
{
195195
try
196196
{
197-
IScheduleHandle handle = this.scheduledTaskClient.GetScheduleHandle(id);
197+
ScheduleClient handle = this.scheduledTaskClient.GetDefaultScheduleClient(id);
198198
await handle.DeleteAsync();
199199
return this.NoContent();
200200
}
@@ -219,7 +219,7 @@ public async Task<ActionResult<ScheduleDescription>> PauseSchedule(string id)
219219
{
220220
try
221221
{
222-
IScheduleHandle handle = this.scheduledTaskClient.GetScheduleHandle(id);
222+
ScheduleClient handle = this.scheduledTaskClient.GetDefaultScheduleClient(id);
223223
await handle.PauseAsync();
224224
return this.Ok(await handle.DescribeAsync());
225225
}
@@ -244,7 +244,7 @@ public async Task<ActionResult<ScheduleDescription>> ResumeSchedule(string id)
244244
{
245245
try
246246
{
247-
IScheduleHandle handle = this.scheduledTaskClient.GetScheduleHandle(id);
247+
ScheduleClient handle = this.scheduledTaskClient.GetDefaultScheduleClient(id);
248248
await handle.ResumeAsync();
249249
return this.Ok(await handle.DescribeAsync());
250250
}

src/ScheduledTasks/Client/ScheduleHandle.cs renamed to src/ScheduledTasks/Client/DefaultScheduleClient.cs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,33 @@ namespace Microsoft.DurableTask.ScheduledTasks;
1111
/// <summary>
1212
/// Represents a handle to a scheduled task, providing operations for managing the schedule.
1313
/// </summary>
14-
class ScheduleHandle : IScheduleHandle
14+
class DefaultScheduleClient : ScheduleClient
1515
{
1616
readonly DurableTaskClient durableTaskClient;
1717
readonly ILogger logger;
1818

1919
/// <summary>
20-
/// Initializes a new instance of the <see cref="ScheduleHandle"/> class.
20+
/// Initializes a new instance of the <see cref="DefaultScheduleClient"/> class.
2121
/// </summary>
2222
/// <param name="client">The durable task client.</param>
2323
/// <param name="scheduleId">The ID of the schedule.</param>
2424
/// <param name="logger">The logger.</param>
2525
/// <exception cref="ArgumentNullException">Thrown if <paramref name="client"/> or <paramref name="scheduleId"/> is null.</exception>
26-
public ScheduleHandle(DurableTaskClient client, string scheduleId, ILogger logger)
26+
public DefaultScheduleClient(DurableTaskClient client, string scheduleId, ILogger logger)
27+
: base(scheduleId)
2728
{
2829
this.durableTaskClient = client ?? throw new ArgumentNullException(nameof(client));
29-
this.ScheduleId = scheduleId ?? throw new ArgumentNullException(nameof(scheduleId));
3030
this.logger = logger ?? throw new ArgumentNullException(nameof(logger));
3131
this.EntityId = new EntityInstanceId(nameof(Schedule), this.ScheduleId);
3232
}
3333

34-
/// <summary>
35-
/// Gets the ID of the schedule.
36-
/// </summary>
37-
public string ScheduleId { get; }
38-
3934
/// <summary>
4035
/// Gets the entity ID of the schedule.
4136
/// </summary>
4237
EntityInstanceId EntityId { get; }
4338

4439
/// <inheritdoc/>
45-
public async Task<ScheduleDescription> DescribeAsync(CancellationToken cancellation = default)
40+
public override async Task<ScheduleDescription> DescribeAsync(CancellationToken cancellation = default)
4641
{
4742
try
4843
{
@@ -91,7 +86,7 @@ public async Task<ScheduleDescription> DescribeAsync(CancellationToken cancellat
9186
}
9287

9388
/// <inheritdoc/>
94-
public async Task PauseAsync(CancellationToken cancellation = default)
89+
public override async Task PauseAsync(CancellationToken cancellation = default)
9590
{
9691
try
9792
{
@@ -126,7 +121,7 @@ public async Task PauseAsync(CancellationToken cancellation = default)
126121
}
127122

128123
/// <inheritdoc/>
129-
public async Task ResumeAsync(CancellationToken cancellation = default)
124+
public override async Task ResumeAsync(CancellationToken cancellation = default)
130125
{
131126
try
132127
{
@@ -161,7 +156,7 @@ public async Task ResumeAsync(CancellationToken cancellation = default)
161156
}
162157

163158
/// <inheritdoc/>
164-
public async Task UpdateAsync(ScheduleUpdateOptions updateOptions, CancellationToken cancellation = default)
159+
public override async Task UpdateAsync(ScheduleUpdateOptions updateOptions, CancellationToken cancellation = default)
165160
{
166161
try
167162
{
@@ -199,7 +194,7 @@ public async Task UpdateAsync(ScheduleUpdateOptions updateOptions, CancellationT
199194
// TODO: verify deleting non existent wont throw exception
200195

201196
/// <inheritdoc/>
202-
public async Task DeleteAsync(CancellationToken cancellation = default)
197+
public override async Task DeleteAsync(CancellationToken cancellation = default)
203198
{
204199
try
205200
{

src/ScheduledTasks/Client/IScheduleHandle.cs

Lines changed: 0 additions & 51 deletions
This file was deleted.

src/ScheduledTasks/Client/IScheduledTaskClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public interface IScheduledTaskClient
1313
/// </summary>
1414
/// <param name="scheduleId">The ID of the schedule.</param>
1515
/// <returns>A handle to manage the schedule.</returns>
16-
IScheduleHandle GetScheduleHandle(string scheduleId);
16+
ScheduleClient GetDefaultScheduleClient(string scheduleId);
1717

1818
/// <summary>
1919
/// Gets a schedule description by its ID.
@@ -36,5 +36,5 @@ public interface IScheduledTaskClient
3636
/// <param name="creationOptions">The options for creating the schedule.</param>
3737
/// <param name="cancellation">Optional cancellation token.</param>
3838
/// <returns>A handle to the created schedule.</returns>
39-
Task<IScheduleHandle> CreateScheduleAsync(ScheduleCreationOptions creationOptions, CancellationToken cancellation = default);
39+
Task<ScheduleClient> CreateScheduleAsync(ScheduleCreationOptions creationOptions, CancellationToken cancellation = default);
4040
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
namespace Microsoft.DurableTask.ScheduledTasks;
5+
6+
/// <summary>
7+
/// Represents a handle to a schedule, allowing operations on a specific schedule instance.
8+
/// </summary>
9+
public abstract class ScheduleClient
10+
{
11+
/// <summary>
12+
/// Initializes a new instance of the <see cref="ScheduleClient"/> class.
13+
/// </summary>
14+
/// <param name="scheduleId">Id of schedule.</param>
15+
protected ScheduleClient(string scheduleId)
16+
{
17+
this.ScheduleId = Check.NotNullOrEmpty(scheduleId, nameof(scheduleId));
18+
}
19+
20+
/// <summary>
21+
/// Gets the ID of this schedule.
22+
/// </summary>
23+
public string ScheduleId { get; }
24+
25+
/// <summary>
26+
/// Retrieves the current details of this schedule.
27+
/// </summary>
28+
/// <param name="cancellation">The cancellation token that can be used to cancel the operation.</param>
29+
/// <returns>A task that returns the schedule details when complete.</returns>
30+
public abstract Task<ScheduleDescription> DescribeAsync(CancellationToken cancellation = default);
31+
32+
/// <summary>
33+
/// Deletes this schedule.
34+
/// </summary>
35+
/// <remarks>
36+
/// The schedule will stop executing and be removed from the system.
37+
/// </remarks>
38+
/// <param name="cancellation">The cancellation token that can be used to cancel the operation.</param>
39+
/// <returns>A task that completes when the schedule has been deleted.</returns>
40+
public abstract Task DeleteAsync(CancellationToken cancellation = default);
41+
42+
/// <summary>
43+
/// Pauses this schedule.
44+
/// </summary>
45+
/// <remarks>
46+
/// The schedule will stop executing but remain in the system.
47+
/// </remarks>
48+
/// <param name="cancellation">The cancellation token that can be used to cancel the operation.</param>
49+
/// <returns>A task that completes when the schedule has been paused.</returns>
50+
public abstract Task PauseAsync(CancellationToken cancellation = default);
51+
52+
/// <summary>
53+
/// Resumes this schedule.
54+
/// </summary>
55+
/// <remarks>
56+
/// The schedule will continue executing from where it was paused.
57+
/// </remarks>
58+
/// <param name="cancellation">The cancellation token that can be used to cancel the operation.</param>
59+
/// <returns>A task that completes when the schedule has been resumed.</returns>
60+
public abstract Task ResumeAsync(CancellationToken cancellation = default);
61+
62+
/// <summary>
63+
/// Updates this schedule with new configuration.
64+
/// </summary>
65+
/// <remarks>
66+
/// The schedule will continue executing with the new configuration.
67+
/// </remarks>
68+
/// <param name="updateOptions">The options for updating the schedule configuration.</param>
69+
/// <param name="cancellation">The cancellation token that can be used to cancel the operation.</param>
70+
/// <returns>A task that completes when the schedule has been updated.</returns>
71+
public abstract Task UpdateAsync(ScheduleUpdateOptions updateOptions, CancellationToken cancellation = default);
72+
}

src/ScheduledTasks/Client/ScheduledTaskClient.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class ScheduledTaskClient(DurableTaskClient durableTaskClient, ILogger lo
1717
readonly ILogger logger = Check.NotNull(logger, nameof(logger));
1818

1919
/// <inheritdoc/>
20-
public async Task<IScheduleHandle> CreateScheduleAsync(ScheduleCreationOptions creationOptions, CancellationToken cancellation = default)
20+
public async Task<ScheduleClient> CreateScheduleAsync(ScheduleCreationOptions creationOptions, CancellationToken cancellation = default)
2121
{
2222
Check.NotNull(creationOptions, nameof(creationOptions));
2323
this.logger.ClientCreatingSchedule(creationOptions);
@@ -43,7 +43,7 @@ public async Task<IScheduleHandle> CreateScheduleAsync(ScheduleCreationOptions c
4343
}
4444

4545
// Return a handle to the schedule
46-
return new ScheduleHandle(this.durableTaskClient, scheduleId, this.logger);
46+
return new DefaultScheduleClient(this.durableTaskClient, scheduleId, this.logger);
4747
}
4848
catch (OperationCanceledException ex)
4949
{
@@ -108,10 +108,10 @@ public async Task<IScheduleHandle> CreateScheduleAsync(ScheduleCreationOptions c
108108
}
109109

110110
/// <inheritdoc/>
111-
public IScheduleHandle GetScheduleHandle(string scheduleId)
111+
public ScheduleClient GetDefaultScheduleClient(string scheduleId)
112112
{
113113
Check.NotNullOrEmpty(scheduleId, nameof(scheduleId));
114-
return new ScheduleHandle(this.durableTaskClient, scheduleId, this.logger);
114+
return new DefaultScheduleClient(this.durableTaskClient, scheduleId, this.logger);
115115
}
116116

117117
/// <inheritdoc/>

0 commit comments

Comments
 (0)