Skip to content

Commit 46b01e4

Browse files
committed
warning fix
1 parent 5749aeb commit 46b01e4

27 files changed

Lines changed: 176 additions & 135 deletions

src/ExportHistory/Activities/ExportInstanceHistoryActivity.cs

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,18 @@ namespace Microsoft.DurableTask.ExportHistory;
1818
/// <summary>
1919
/// Activity that exports one orchestration instance history to the configured blob destination.
2020
/// </summary>
21+
/// <remarks>
22+
/// Initializes a new instance of the <see cref="ExportInstanceHistoryActivity"/> class.
23+
/// </remarks>
2124
[DurableTask]
22-
public class ExportInstanceHistoryActivity : TaskActivity<ExportRequest, ExportResult>
25+
public class ExportInstanceHistoryActivity(
26+
IDurableTaskClientProvider clientProvider,
27+
ILogger<ExportInstanceHistoryActivity> logger,
28+
IOptions<ExportHistoryStorageOptions> storageOptions) : TaskActivity<ExportRequest, ExportResult>
2329
{
24-
readonly IDurableTaskClientProvider clientProvider;
25-
readonly ILogger<ExportInstanceHistoryActivity> logger;
26-
readonly ExportHistoryStorageOptions storageOptions;
27-
28-
/// <summary>
29-
/// Initializes a new instance of the <see cref="ExportInstanceHistoryActivity"/> class.
30-
/// </summary>
31-
public ExportInstanceHistoryActivity(
32-
IDurableTaskClientProvider clientProvider,
33-
ILogger<ExportInstanceHistoryActivity> logger,
34-
IOptions<ExportHistoryStorageOptions> storageOptions)
35-
{
36-
this.clientProvider = Check.NotNull(clientProvider, nameof(clientProvider));
37-
this.logger = Check.NotNull(logger, nameof(logger));
38-
this.storageOptions = Check.NotNull(storageOptions?.Value, nameof(storageOptions));
39-
}
30+
readonly IDurableTaskClientProvider clientProvider = Check.NotNull(clientProvider, nameof(clientProvider));
31+
readonly ILogger<ExportInstanceHistoryActivity> logger = Check.NotNull(logger, nameof(logger));
32+
readonly ExportHistoryStorageOptions storageOptions = Check.NotNull(storageOptions?.Value, nameof(storageOptions));
4033

4134
/// <inheritdoc/>
4235
public override async Task<ExportResult> RunAsync(TaskActivityContext context, ExportRequest input)
@@ -236,7 +229,7 @@ await containerClient.CreateIfNotExistsAsync(
236229
// Upload content
237230
byte[] contentBytes = Encoding.UTF8.GetBytes(content);
238231

239-
if (format.Kind.Equals("jsonl", StringComparison.InvariantCultureIgnoreCase))
232+
if (format.Kind.Equals("jsonl", StringComparison.OrdinalIgnoreCase))
240233
{
241234
// Compress with gzip
242235
using MemoryStream compressedStream = new();

src/ExportHistory/Client/DefaultExportHistoryClient.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using Microsoft.DurableTask.Client;
55
using Microsoft.DurableTask.Client.Entities;
6-
using Microsoft.DurableTask.Entities;
76
using Microsoft.Extensions.Logging;
87

98
namespace Microsoft.DurableTask.ExportHistory;
@@ -35,8 +34,7 @@ public override async Task<ExportHistoryJobClient> CreateJobAsync(
3534
this.durableTaskClient,
3635
options.JobId,
3736
this.logger,
38-
this.storageOptions
39-
);
37+
this.storageOptions);
4038

4139
// Create the export job using the client (validation already done in constructor)
4240
await exportHistoryJobClient.CreateAsync(options, cancellation);
@@ -189,4 +187,4 @@ static bool MatchesFilter(ExportJobState state, ExportJobQuery filter)
189187

190188
return statusMatches && createdFromMatches && createdToMatches;
191189
}
192-
}
190+
}

src/ExportHistory/Client/DefaultExportHistoryJobClient.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@ public sealed class DefaultExportHistoryJobClient(
1616
DurableTaskClient durableTaskClient,
1717
string jobId,
1818
ILogger logger,
19-
ExportHistoryStorageOptions storageOptions
20-
) : ExportHistoryJobClient(jobId)
19+
ExportHistoryStorageOptions storageOptions) : ExportHistoryJobClient(jobId)
2120
{
2221
readonly DurableTaskClient durableTaskClient = Check.NotNull(durableTaskClient, nameof(durableTaskClient));
2322
readonly ILogger logger = Check.NotNull(logger, nameof(logger));
2423
readonly ExportHistoryStorageOptions storageOptions = Check.NotNull(storageOptions, nameof(storageOptions));
2524
readonly EntityInstanceId entityId = new(nameof(ExportJob), jobId);
2625

26+
/// <inheritdoc/>
2727
public override async Task CreateAsync(ExportJobCreationOptions options, CancellationToken cancellation = default)
2828
{
2929
try
3030
{
3131
Check.NotNull(options, nameof(options));
3232

3333
// Determine default prefix based on mode if not already set
34-
string? defaultPrefix = $"{options.Mode.ToString().ToLower()}/";
34+
string? defaultPrefix = $"{options.Mode.ToString().ToLower(System.Globalization.CultureInfo.CurrentCulture)}/";
3535

3636
// If destination is not provided, construct it from storage options
3737
ExportJobCreationOptions optionsWithDestination = options;
@@ -57,10 +57,10 @@ public override async Task CreateAsync(ExportJobCreationOptions options, Cancell
5757
optionsWithDestination = options with { Destination = destinationWithPrefix };
5858
}
5959

60-
ExportJobOperationRequest request =
60+
ExportJobOperationRequest request =
6161
new ExportJobOperationRequest(
62-
this.entityId,
63-
nameof(ExportJob.Create),
62+
this.entityId,
63+
nameof(ExportJob.Create),
6464
optionsWithDestination);
6565

6666
string instanceId = await this.durableTaskClient
@@ -72,8 +72,8 @@ public override async Task CreateAsync(ExportJobCreationOptions options, Cancell
7272
// Wait for the orchestration to complete
7373
OrchestrationMetadata state = await this.durableTaskClient
7474
.WaitForInstanceCompletionAsync(
75-
instanceId,
76-
true,
75+
instanceId,
76+
true,
7777
cancellation);
7878

7979
if (state.RuntimeStatus != OrchestrationRuntimeStatus.Completed)
@@ -98,6 +98,8 @@ public override async Task CreateAsync(ExportJobCreationOptions options, Cancell
9898

9999
// TODO: there is no atomicity guarantee of deleting entity and purging the orchestrator
100100
// Add sweeping process to clean up orphaned orchestrations failed to be purged
101+
102+
/// <inheritdoc/>
101103
public override async Task DeleteAsync(CancellationToken cancellation = default)
102104
{
103105
try
@@ -129,6 +131,7 @@ public override async Task DeleteAsync(CancellationToken cancellation = default)
129131
}
130132
}
131133

134+
/// <inheritdoc/>
132135
public override async Task<ExportJobDescription> DescribeAsync(CancellationToken cancellation = default)
133136
{
134137
try
@@ -211,5 +214,3 @@ await this.durableTaskClient.TerminateInstanceAsync(
211214
}
212215
}
213216
}
214-
215-
Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,40 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
using Microsoft.DurableTask.Client;
5-
using Microsoft.DurableTask.Entities;
6-
74
namespace Microsoft.DurableTask.ExportHistory;
85

96
/// <summary>
107
/// Convenience client for managing export jobs via entity signals and reads.
118
/// </summary>
129
public abstract class ExportHistoryClient
1310
{
11+
/// <summary>
12+
/// Creates a new export job.
13+
/// </summary>
14+
/// <param name="options">The options for the export job.</param>
15+
/// <param name="cancellation">The cancellation token.</param>
16+
/// <returns>A task representing the asynchronous operation.</returns>
1417
public abstract Task<ExportHistoryJobClient> CreateJobAsync(ExportJobCreationOptions options, CancellationToken cancellation = default);
18+
19+
/// <summary>
20+
/// Gets an export job.
21+
/// </summary>
22+
/// <param name="jobId">The ID of the export job.</param>
23+
/// <param name="cancellation">The cancellation token.</param>
24+
/// <returns>A task representing the asynchronous operation.</returns>
1525
public abstract Task<ExportJobDescription> GetJobAsync(string jobId, CancellationToken cancellation = default);
1626

27+
/// <summary>
28+
/// Lists export jobs.
29+
/// </summary>
30+
/// <param name="filter">The filter for the export jobs.</param>
31+
/// <returns>A task representing the asynchronous operation.</returns>
1732
public abstract AsyncPageable<ExportJobDescription> ListJobsAsync(ExportJobQuery? filter = null);
33+
34+
/// <summary>
35+
/// Gets an export job client.
36+
/// </summary>
37+
/// <param name="jobId">The ID of the export job.</param>
38+
/// <returns>The export job client.</returns>
1839
public abstract ExportHistoryJobClient GetJobClient(string jobId);
19-
}
40+
}

src/ExportHistory/Client/ExportHistoryJobClient.cs

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,40 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
using Microsoft.DurableTask.Client;
5-
using Microsoft.DurableTask.Entities;
6-
74
namespace Microsoft.DurableTask.ExportHistory;
85

96
/// <summary>
107
/// Convenience client for managing export jobs via entity signals and reads.
118
/// </summary>
12-
public abstract class ExportHistoryJobClient
9+
/// <remarks>
10+
/// Initializes a new instance of the <see cref="ExportHistoryJobClient"/> class.
11+
/// </remarks>
12+
public abstract class ExportHistoryJobClient(string jobId)
1313
{
14-
public readonly string JobId;
15-
1614
/// <summary>
17-
/// Initializes a new instance of the <see cref="ExportJobClient"/> class.
15+
/// The ID of the export job.
1816
/// </summary>
19-
protected ExportHistoryJobClient(string jobId)
20-
{
21-
this.JobId = Check.NotNullOrEmpty(jobId, nameof(jobId));
22-
}
17+
protected readonly string JobId = Check.NotNullOrEmpty(jobId, nameof(jobId));
2318

19+
/// <summary>
20+
/// Creates a new export job.
21+
/// </summary>
22+
/// <param name="options">The options for the export job.</param>
23+
/// <param name="cancellation">The cancellation token.</param>
24+
/// <returns>A task representing the asynchronous operation.</returns>
2425
public abstract Task CreateAsync(ExportJobCreationOptions options, CancellationToken cancellation = default);
26+
27+
/// <summary>
28+
/// Describes the export job.
29+
/// </summary>
30+
/// <param name="cancellation">The cancellation token.</param>
31+
/// <returns>A task representing the asynchronous operation.</returns>
2532
public abstract Task<ExportJobDescription> DescribeAsync(CancellationToken cancellation = default);
33+
34+
/// <summary>
35+
/// Deletes the export job.
36+
/// </summary>
37+
/// <param name="cancellation">The cancellation token.</param>
38+
/// <returns>A task representing the asynchronous operation.</returns>
2639
public abstract Task DeleteAsync(CancellationToken cancellation = default);
2740
}
28-
29-

src/ExportHistory/Constants/ExportHistoryConstants.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ static class ExportHistoryConstants
1010
{
1111
/// <summary>
1212
/// The prefix pattern used for generating export job orchestrator instance IDs.
13-
/// Format: "ExportJob-{jobId}"
13+
/// Format: "ExportJob-{jobId}".
1414
/// </summary>
1515
public const string OrchestratorInstanceIdPrefix = "ExportJob-";
1616

src/ExportHistory/Entity/ExportJob.cs

Lines changed: 43 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
using Microsoft.DurableTask.Client;
54
using Microsoft.DurableTask.Entities;
65
using Microsoft.Extensions.Logging;
76

@@ -39,7 +38,7 @@ public void Create(TaskEntityContext context, ExportJobCreationOptions creationO
3938
// Note: RuntimeStatus validation already done in ExportJobCreationOptions constructor
4039
// Note: Destination should be populated by the client before reaching here
4140
Verify.NotNull(creationOptions.Destination, nameof(creationOptions.Destination));
42-
41+
4342
ExportJobConfiguration config = new ExportJobConfiguration(
4443
Mode: creationOptions.Mode,
4544
Filter: new ExportFilter(
@@ -114,48 +113,6 @@ public void Run(TaskEntityContext context)
114113
}
115114
}
116115

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-
159116
/// <summary>
160117
/// Commits a checkpoint snapshot with progress updates and optional failures.
161118
/// </summary>
@@ -292,4 +249,46 @@ public void Delete(TaskEntityContext context)
292249
throw;
293250
}
294251
}
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+
}
295294
}

src/ExportHistory/Entity/ExportJobOperations.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,3 @@ static class ExportJobOperations
1717
/// </summary>
1818
public const string Delete = "Delete";
1919
}
20-

src/ExportHistory/Exception/ExportJobClientValidationException.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,3 @@ public ExportJobClientValidationException(string jobId, string message, Exceptio
3636
/// </summary>
3737
public string JobId { get; }
3838
}
39-

src/ExportHistory/Exception/ExportJobInvalidTransitionException.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,3 @@ public ExportJobInvalidTransitionException(string jobId, ExportJobStatus fromSta
6161
/// </summary>
6262
public string OperationName { get; }
6363
}
64-

0 commit comments

Comments
 (0)