|
1 | 1 | // Copyright (c) Microsoft Corporation. |
2 | 2 | // Licensed under the MIT License. |
3 | 3 |
|
4 | | -using Microsoft.DurableTask.Client; |
5 | 4 | using Microsoft.DurableTask.Entities; |
6 | 5 | using Microsoft.Extensions.Logging; |
7 | 6 |
|
@@ -39,7 +38,7 @@ public void Create(TaskEntityContext context, ExportJobCreationOptions creationO |
39 | 38 | // Note: RuntimeStatus validation already done in ExportJobCreationOptions constructor |
40 | 39 | // Note: Destination should be populated by the client before reaching here |
41 | 40 | Verify.NotNull(creationOptions.Destination, nameof(creationOptions.Destination)); |
42 | | - |
| 41 | + |
43 | 42 | ExportJobConfiguration config = new ExportJobConfiguration( |
44 | 43 | Mode: creationOptions.Mode, |
45 | 44 | Filter: new ExportFilter( |
@@ -114,48 +113,6 @@ public void Run(TaskEntityContext context) |
114 | 113 | } |
115 | 114 | } |
116 | 115 |
|
117 | | - void StartExportOrchestration(TaskEntityContext context) |
118 | | - { |
119 | | - try |
120 | | - { |
121 | | - // Use a fixed instance ID based on job ID to ensure only one orchestrator runs per job |
122 | | - // This prevents concurrent orchestrators if Run is called multiple times |
123 | | - string instanceId = ExportHistoryConstants.GetOrchestratorInstanceId(context.Id.Key); |
124 | | - StartOrchestrationOptions startOrchestrationOptions = new StartOrchestrationOptions(instanceId); |
125 | | - |
126 | | - logger.ExportJobOperationInfo( |
127 | | - context.Id.Key, |
128 | | - nameof(this.StartExportOrchestration), |
129 | | - $"Starting new orchestration named '{nameof(ExportJobOrchestrator)}' with instance ID: {instanceId}"); |
130 | | - |
131 | | - context.ScheduleNewOrchestration( |
132 | | - new TaskName(nameof(ExportJobOrchestrator)), |
133 | | - new ExportJobRunRequest(context.Id), |
134 | | - startOrchestrationOptions); |
135 | | - |
136 | | - this.State.OrchestratorInstanceId = instanceId; |
137 | | - this.State.LastModifiedAt = DateTimeOffset.UtcNow; |
138 | | - } |
139 | | - catch (Exception ex) |
140 | | - { |
141 | | - // Mark job as failed and record the exception |
142 | | - this.State.Status = ExportJobStatus.Failed; |
143 | | - this.State.LastError = ex.Message; |
144 | | - this.State.LastModifiedAt = DateTimeOffset.UtcNow; |
145 | | - |
146 | | - logger.ExportJobOperationError( |
147 | | - context.Id.Key, |
148 | | - nameof(this.StartExportOrchestration), |
149 | | - "Failed to start export orchestration", |
150 | | - ex); |
151 | | - } |
152 | | - } |
153 | | - |
154 | | - bool CanTransitionTo(string operationName, ExportJobStatus targetStatus) |
155 | | - { |
156 | | - return ExportJobTransitions.IsValidTransition(operationName, this.State.Status, targetStatus); |
157 | | - } |
158 | | - |
159 | 116 | /// <summary> |
160 | 117 | /// Commits a checkpoint snapshot with progress updates and optional failures. |
161 | 118 | /// </summary> |
@@ -292,4 +249,46 @@ public void Delete(TaskEntityContext context) |
292 | 249 | throw; |
293 | 250 | } |
294 | 251 | } |
| 252 | + |
| 253 | + void StartExportOrchestration(TaskEntityContext context) |
| 254 | + { |
| 255 | + try |
| 256 | + { |
| 257 | + // Use a fixed instance ID based on job ID to ensure only one orchestrator runs per job |
| 258 | + // This prevents concurrent orchestrators if Run is called multiple times |
| 259 | + string instanceId = ExportHistoryConstants.GetOrchestratorInstanceId(context.Id.Key); |
| 260 | + StartOrchestrationOptions startOrchestrationOptions = new StartOrchestrationOptions(instanceId); |
| 261 | + |
| 262 | + logger.ExportJobOperationInfo( |
| 263 | + context.Id.Key, |
| 264 | + nameof(this.StartExportOrchestration), |
| 265 | + $"Starting new orchestration named '{nameof(ExportJobOrchestrator)}' with instance ID: {instanceId}"); |
| 266 | + |
| 267 | + context.ScheduleNewOrchestration( |
| 268 | + new TaskName(nameof(ExportJobOrchestrator)), |
| 269 | + new ExportJobRunRequest(context.Id), |
| 270 | + startOrchestrationOptions); |
| 271 | + |
| 272 | + this.State.OrchestratorInstanceId = instanceId; |
| 273 | + this.State.LastModifiedAt = DateTimeOffset.UtcNow; |
| 274 | + } |
| 275 | + catch (Exception ex) |
| 276 | + { |
| 277 | + // Mark job as failed and record the exception |
| 278 | + this.State.Status = ExportJobStatus.Failed; |
| 279 | + this.State.LastError = ex.Message; |
| 280 | + this.State.LastModifiedAt = DateTimeOffset.UtcNow; |
| 281 | + |
| 282 | + logger.ExportJobOperationError( |
| 283 | + context.Id.Key, |
| 284 | + nameof(this.StartExportOrchestration), |
| 285 | + "Failed to start export orchestration", |
| 286 | + ex); |
| 287 | + } |
| 288 | + } |
| 289 | + |
| 290 | + bool CanTransitionTo(string operationName, ExportJobStatus targetStatus) |
| 291 | + { |
| 292 | + return ExportJobTransitions.IsValidTransition(operationName, this.State.Status, targetStatus); |
| 293 | + } |
295 | 294 | } |
0 commit comments