-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First attempt at streaming zip, doesn't work
Alas, this fails (when a ProjectController method is added to call PrepareLdmlZip) with "System.InvalidOperationException: Synchronous operations are disallowed. Call WriteAsync or set AllowSynchronousIO to true instead." We'll have to change this to prepare the entire zip file first, then send it.
- Loading branch information
Showing
6 changed files
with
106 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System.Diagnostics; | ||
using LexBoxApi.Otel; | ||
using OpenTelemetry.Trace; | ||
using Quartz; | ||
|
||
namespace LexBoxApi.Jobs; | ||
|
||
public abstract class DelayedLexJob() : LexJob | ||
{ | ||
protected static async Task QueueJob(ISchedulerFactory schedulerFactory, | ||
JobKey key, | ||
JobDataMap data, | ||
TimeSpan delay, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
var now = DateTime.UtcNow; | ||
data[nameof(JobTriggerTraceId)] = Activity.Current?.Context.TraceId.ToHexString() ?? string.Empty; | ||
data[nameof(JobTriggerSpanParentId)] = Activity.Current?.Context.SpanId.ToHexString() ?? string.Empty; | ||
var trigger = TriggerBuilder.Create() | ||
.WithIdentity(key.Name + "_Trigger", key.Group) | ||
.StartAt(now.Add(delay)) | ||
.ForJob(key.Name, key.Group) | ||
.UsingJobData(data) | ||
.Build(); | ||
var scheduler = await schedulerFactory.GetScheduler(cancellationToken); | ||
await scheduler.ScheduleJob(trigger, cancellationToken); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using Quartz; | ||
|
||
namespace LexBoxApi.Jobs; | ||
|
||
public class DeleteTempDirectoryJob() : DelayedLexJob | ||
{ | ||
public static async Task Queue(ISchedulerFactory schedulerFactory, | ||
string path, | ||
TimeSpan delay, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
await QueueJob(schedulerFactory, | ||
Key, | ||
new JobDataMap { { nameof(Path), path } }, | ||
delay, | ||
cancellationToken); | ||
} | ||
|
||
public static JobKey Key { get; } = new(nameof(DeleteTempDirectoryJob), "CleanupJobs"); | ||
public string? Path { get; set; } | ||
|
||
protected override Task ExecuteJob(IJobExecutionContext context) | ||
{ | ||
ArgumentException.ThrowIfNullOrEmpty(Path); | ||
return Task.Run(() => | ||
{ | ||
if (Directory.Exists(Path)) Directory.Delete(Path, true); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters