|
3 | 3 |
|
4 | 4 | using Microsoft.DurableTask.Client; |
5 | 5 | using Microsoft.DurableTask.Client.Entities; |
6 | | -using Microsoft.DurableTask.Entities; |
7 | 6 | using Microsoft.Extensions.Logging; |
8 | 7 |
|
9 | 8 | namespace Microsoft.DurableTask.ScheduledTasks; |
@@ -57,32 +56,16 @@ public override async Task<ScheduleClient> CreateScheduleAsync(ScheduleCreationO |
57 | 56 |
|
58 | 57 | try |
59 | 58 | { |
60 | | - EntityInstanceId entityId = new EntityInstanceId(nameof(Schedule), scheduleId); |
61 | | - EntityMetadata<ScheduleState>? metadata = await this.durableTaskClient.Entities.GetEntityAsync<ScheduleState>(entityId, cancellation); |
| 59 | + // Get schedule client first |
| 60 | + ScheduleClient scheduleClient = this.GetScheduleClient(scheduleId); |
62 | 61 |
|
63 | | - if (metadata == null || metadata.State.Status == ScheduleStatus.Uninitialized) |
64 | | - { |
65 | | - return null; |
66 | | - } |
67 | | - |
68 | | - ScheduleState state = metadata.State; |
69 | | - ScheduleConfiguration? config = state.ScheduleConfiguration; |
70 | | - |
71 | | - return new ScheduleDescription |
72 | | - { |
73 | | - ScheduleId = scheduleId, |
74 | | - OrchestrationName = config?.OrchestrationName, |
75 | | - OrchestrationInput = config?.OrchestrationInput, |
76 | | - OrchestrationInstanceId = config?.OrchestrationInstanceId, |
77 | | - StartAt = config?.StartAt, |
78 | | - EndAt = config?.EndAt, |
79 | | - Interval = config?.Interval, |
80 | | - StartImmediatelyIfLate = config?.StartImmediatelyIfLate, |
81 | | - Status = state.Status, |
82 | | - ExecutionToken = state.ExecutionToken, |
83 | | - LastRunAt = state.LastRunAt, |
84 | | - NextRunAt = state.NextRunAt, |
85 | | - }; |
| 62 | + // Call DescribeAsync which handles all the entity state mapping |
| 63 | + return await scheduleClient.DescribeAsync(cancellation); |
| 64 | + } |
| 65 | + catch (ScheduleNotFoundException) |
| 66 | + { |
| 67 | + // Return null if schedule not found |
| 68 | + return null; |
86 | 69 | } |
87 | 70 | catch (OperationCanceledException) when (cancellation.IsCancellationRequested) |
88 | 71 | { |
|
0 commit comments