Skip to content

Commit da7bc00

Browse files
committed
fb
1 parent f63d58c commit da7bc00

File tree

5 files changed

+27
-52
lines changed

5 files changed

+27
-52
lines changed

samples/ScheduleConsoleApp/Program.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252

5353
// Run the schedule operations
5454
ScheduledTaskClient scheduledTaskClient = host.Services.GetRequiredService<ScheduledTaskClient>();
55-
ScheduleOperations scheduleOperations = new ScheduleOperations(scheduledTaskClient);
56-
await scheduleOperations.RunAsync();
55+
await ScheduleDemo.RunDemoAsync(scheduledTaskClient);
5756

5857
await host.StopAsync();

samples/ScheduleConsoleApp/ScheduleOperations.cs renamed to samples/ScheduleConsoleApp/ScheduleDemo.cs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,44 @@
66

77
namespace ScheduleConsoleApp;
88

9-
class ScheduleOperations(ScheduledTaskClient scheduledTaskClient)
9+
/// <summary>
10+
/// Demonstrates various schedule operations in a sample application.
11+
/// </summary>
12+
static class ScheduleDemo
1013
{
11-
readonly ScheduledTaskClient scheduledTaskClient = scheduledTaskClient ?? throw new ArgumentNullException(nameof(scheduledTaskClient));
12-
13-
public async Task RunAsync()
14+
public static async Task RunDemoAsync(ScheduledTaskClient scheduledTaskClient)
1415
{
16+
ArgumentNullException.ThrowIfNull(scheduledTaskClient);
17+
1518
try
1619
{
17-
await this.DeleteExistingSchedulesAsync();
18-
await this.CreateAndManageScheduleAsync();
20+
await DeleteExistingSchedulesAsync(scheduledTaskClient);
21+
await CreateAndManageScheduleAsync(scheduledTaskClient);
1922
}
2023
catch (Exception ex)
2124
{
2225
Console.WriteLine($"One of your schedule operations failed, please fix and rerun: {ex.Message}");
2326
}
2427
}
2528

26-
async Task DeleteExistingSchedulesAsync()
29+
static async Task DeleteExistingSchedulesAsync(ScheduledTaskClient scheduledTaskClient)
2730
{
2831
// Define the initial query with the desired page size
2932
ScheduleQuery query = new ScheduleQuery { PageSize = 100 };
3033

3134
// Retrieve the pageable collection of schedule IDs
32-
AsyncPageable<ScheduleDescription> schedules = this.scheduledTaskClient.ListSchedulesAsync(query);
35+
AsyncPageable<ScheduleDescription> schedules = scheduledTaskClient.ListSchedulesAsync(query);
3336

3437
// Delete each existing schedule
3538
await foreach (ScheduleDescription schedule in schedules)
3639
{
37-
ScheduleClient scheduleClient1 = this.scheduledTaskClient.GetScheduleClient(schedule.ScheduleId);
38-
await scheduleClient1.DeleteAsync();
40+
ScheduleClient scheduleClient = scheduledTaskClient.GetScheduleClient(schedule.ScheduleId);
41+
await scheduleClient.DeleteAsync();
3942
Console.WriteLine($"Deleted schedule {schedule.ScheduleId}");
4043
}
4144
}
4245

43-
async Task CreateAndManageScheduleAsync()
46+
static async Task CreateAndManageScheduleAsync(ScheduledTaskClient scheduledTaskClient)
4447
{
4548
// Create schedule options that runs every 4 seconds
4649
ScheduleCreationOptions scheduleOptions = new ScheduleCreationOptions(
@@ -53,7 +56,7 @@ async Task CreateAndManageScheduleAsync()
5356
};
5457

5558
// Create the schedule and get a handle to it
56-
ScheduleClient scheduleClient = await this.scheduledTaskClient.CreateScheduleAsync(scheduleOptions);
59+
ScheduleClient scheduleClient = await scheduledTaskClient.CreateScheduleAsync(scheduleOptions);
5760

5861
// Get and print the initial schedule description
5962
await PrintScheduleDescriptionAsync(scheduleClient);

src/ScheduledTasks/Client/ScheduleClientImpl.cs

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,7 @@ public override async Task CreateAsync(ScheduleCreationOptions creationOptions,
6565
}
6666
catch (Exception ex)
6767
{
68-
this.logger.ClientError(
69-
nameof(this.CreateAsync),
70-
this.ScheduleId,
71-
ex);
68+
this.logger.ClientError(nameof(this.CreateAsync), this.ScheduleId, ex);
7269

7370
throw;
7471
}
@@ -115,10 +112,7 @@ public override async Task<ScheduleDescription> DescribeAsync(CancellationToken
115112
}
116113
catch (Exception ex)
117114
{
118-
this.logger.ClientError(
119-
nameof(this.DescribeAsync),
120-
this.ScheduleId,
121-
ex);
115+
this.logger.ClientError(nameof(this.DescribeAsync), this.ScheduleId, ex);
122116

123117
throw;
124118
}
@@ -152,10 +146,7 @@ public override async Task PauseAsync(CancellationToken cancellation = default)
152146
}
153147
catch (Exception ex)
154148
{
155-
this.logger.ClientError(
156-
nameof(this.PauseAsync),
157-
this.ScheduleId,
158-
ex);
149+
this.logger.ClientError(nameof(this.PauseAsync), this.ScheduleId, ex);
159150

160151
throw;
161152
}
@@ -189,10 +180,7 @@ public override async Task ResumeAsync(CancellationToken cancellation = default)
189180
}
190181
catch (Exception ex)
191182
{
192-
this.logger.ClientError(
193-
nameof(this.ResumeAsync),
194-
this.ScheduleId,
195-
ex);
183+
this.logger.ClientError(nameof(this.ResumeAsync), this.ScheduleId, ex);
196184

197185
throw;
198186
}
@@ -227,10 +215,7 @@ public override async Task UpdateAsync(ScheduleUpdateOptions updateOptions, Canc
227215
}
228216
catch (Exception ex)
229217
{
230-
this.logger.ClientError(
231-
nameof(this.UpdateAsync),
232-
this.ScheduleId,
233-
ex);
218+
this.logger.ClientError(nameof(this.UpdateAsync), this.ScheduleId, ex);
234219

235220
throw;
236221
}
@@ -264,10 +249,7 @@ public override async Task DeleteAsync(CancellationToken cancellation = default)
264249
}
265250
catch (Exception ex)
266251
{
267-
this.logger.ClientError(
268-
nameof(this.DeleteAsync),
269-
this.ScheduleId,
270-
ex);
252+
this.logger.ClientError(nameof(this.DeleteAsync), this.ScheduleId, ex);
271253

272254
throw;
273255
}

src/ScheduledTasks/Client/ScheduledTaskClientImpl.cs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,7 @@ public override async Task<ScheduleClient> CreateScheduleAsync(ScheduleCreationO
4040
}
4141
catch (Exception ex)
4242
{
43-
this.logger.ClientError(
44-
nameof(this.CreateScheduleAsync),
45-
creationOptions.ScheduleId,
46-
ex);
43+
this.logger.ClientError(nameof(this.CreateScheduleAsync), creationOptions.ScheduleId, ex);
4744

4845
throw;
4946
}
@@ -74,10 +71,7 @@ public override async Task<ScheduleClient> CreateScheduleAsync(ScheduleCreationO
7471
}
7572
catch (Exception ex)
7673
{
77-
this.logger.ClientError(
78-
nameof(this.GetScheduleAsync),
79-
scheduleId,
80-
ex);
74+
this.logger.ClientError(nameof(this.GetScheduleAsync), scheduleId, ex);
8175

8276
throw;
8377
}
@@ -169,10 +163,7 @@ public override AsyncPageable<ScheduleDescription> ListSchedulesAsync(ScheduleQu
169163
}
170164
catch (Exception ex)
171165
{
172-
this.logger.ClientError(
173-
nameof(this.ListSchedulesAsync),
174-
string.Empty,
175-
ex);
166+
this.logger.ClientError(nameof(this.ListSchedulesAsync), string.Empty, ex);
176167

177168
throw;
178169
}

src/ScheduledTasks/Entity/Schedule.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,8 @@ public void RunSchedule(TaskEntityContext context, string executionToken)
251251

252252
if (this.State.NextRunAt!.Value <= currentTime)
253253
{
254-
this.StartOrchestration(context, currentTime);
255-
this.State.LastRunAt = currentTime;
254+
this.StartOrchestration(context, this.State.NextRunAt!.Value);
255+
this.State.LastRunAt = this.State.NextRunAt!.Value;
256256
this.State.NextRunAt = null;
257257
this.State.NextRunAt = this.DetermineNextRunTime(scheduleConfig);
258258
}

0 commit comments

Comments
 (0)