Browse Source

Fix timeout handling for backups.

pull/926/head
Sebastian 4 years ago
parent
commit
0f3e889567
  1. 10
      backend/src/Squidex.Domain.Apps.Entities/Backup/BackupProcessor.cs
  2. 4
      backend/src/Squidex.Domain.Apps.Entities/Backup/RestoreProcessor.cs
  3. 12
      backend/src/Squidex/Config/Messaging/MessagingServices.cs
  4. 2
      frontend/src/app/framework/angular/pipes/date-time.pipes.spec.ts
  5. 6
      frontend/src/app/framework/utils/date-time.spec.ts
  6. 2
      frontend/src/app/framework/utils/date-time.ts

10
backend/src/Squidex.Domain.Apps.Entities/Backup/BackupProcessor.cs

@ -114,13 +114,11 @@ namespace Squidex.Domain.Apps.Entities.Backup
Handlers = backupHandlerFactory.CreateMany() Handlers = backupHandlerFactory.CreateMany()
}; };
log.LogInformation("Starting new backup with backup id '{backupId}'.", run.Job.Id); log.LogInformation("Starting new backup with backup id '{backupId}' for app {appId}.", run.Job.Id, appId);
state.Value.Jobs.Insert(0, run.Job); state.Value.Jobs.Insert(0, run.Job);
try try
{ {
await state.WriteAsync(run.CancellationToken);
await ProcessAsync(run, run.CancellationToken); await ProcessAsync(run, run.CancellationToken);
} }
finally finally
@ -137,6 +135,8 @@ namespace Squidex.Domain.Apps.Entities.Backup
{ {
try try
{ {
await state.WriteAsync(run.CancellationToken);
await using (var stream = backupArchiveLocation.OpenStream(run.Job.Id)) await using (var stream = backupArchiveLocation.OpenStream(run.Job.Id))
{ {
using (var writer = await backupArchiveLocation.OpenWriterAsync(stream, ct)) using (var writer = await backupArchiveLocation.OpenWriterAsync(stream, ct))
@ -191,10 +191,6 @@ namespace Squidex.Domain.Apps.Entities.Backup
await SetStatusAsync(run, JobStatus.Completed); await SetStatusAsync(run, JobStatus.Completed);
} }
catch (OperationCanceledException)
{
await RemoveAsync(run.Job);
}
catch (Exception ex) catch (Exception ex)
{ {
await SetStatusAsync(run, JobStatus.Failed); await SetStatusAsync(run, JobStatus.Failed);

4
backend/src/Squidex.Domain.Apps.Entities/Backup/RestoreProcessor.cs

@ -113,8 +113,6 @@ namespace Squidex.Domain.Apps.Entities.Backup
state.Value.Job = run.Job; state.Value.Job = run.Job;
try try
{ {
await state.WriteAsync(run.CancellationToken);
await ProcessAsync(run, run.CancellationToken); await ProcessAsync(run, run.CancellationToken);
} }
finally finally
@ -133,6 +131,8 @@ namespace Squidex.Domain.Apps.Entities.Backup
{ {
try try
{ {
await state.WriteAsync(run.CancellationToken);
await LogAsync(run, "Started. The restore process has the following steps:"); await LogAsync(run, "Started. The restore process has the following steps:");
await LogAsync(run, " * Download backup"); await LogAsync(run, " * Download backup");
await LogAsync(run, " * Restore events and attachments."); await LogAsync(run, " * Restore events and attachments.");

12
backend/src/Squidex/Config/Messaging/MessagingServices.cs

@ -91,17 +91,19 @@ namespace Squidex.Config.Messaging
options.Routing.AddFallback(channelFallback); options.Routing.AddFallback(channelFallback);
}); });
services.AddMessaging(channelFallback, isWorker, options =>
{
options.Scheduler = InlineScheduler.Instance;
});
services.AddMessaging(channelBackupStart, isWorker, options => services.AddMessaging(channelBackupStart, isWorker, options =>
{ {
options.Timeout = TimeSpan.FromHours(4);
options.Scheduler = new ParallelScheduler(4); options.Scheduler = new ParallelScheduler(4);
}); });
services.AddMessaging(channelBackupRestore, isWorker, options => services.AddMessaging(channelBackupRestore, isWorker, options =>
{
options.Timeout = TimeSpan.FromHours(24);
options.Scheduler = InlineScheduler.Instance;
});
services.AddMessaging(channelFallback, isWorker, options =>
{ {
options.Scheduler = InlineScheduler.Instance; options.Scheduler = InlineScheduler.Instance;
}); });

2
frontend/src/app/framework/angular/pipes/date-time.pipes.spec.ts

@ -113,7 +113,7 @@ describe('FromNowPipe', () => {
const pipe = new FromNowPipe(); const pipe = new FromNowPipe();
const actual = pipe.transform(DateTime.now().addMinutes(-4)); const actual = pipe.transform(DateTime.now().addMinutes(-4));
const expected = '4 minutes'; const expected = '4 minutes ago';
expect(actual).toBe(expected); expect(actual).toBe(expected);
}); });

6
frontend/src/app/framework/utils/date-time.spec.ts

@ -120,7 +120,7 @@ describe('DateTime', () => {
it('should print to from now string', () => { it('should print to from now string', () => {
const value = DateTime.now().addMinutes(-4); const value = DateTime.now().addMinutes(-4);
const expected = '4 minutes'; const expected = '4 minutes ago';
expect(value.toFromNow()).toBe(expected); expect(value.toFromNow()).toBe(expected);
}); });
@ -231,7 +231,7 @@ describe('DateTime', () => {
it('should format to from now string', () => { it('should format to from now string', () => {
const value = DateTime.now().addMinutes(-4); const value = DateTime.now().addMinutes(-4);
const expected = '4 minuten'; const expected = '4 minuten geleden';
expect(value.toFromNow()).toBe(expected); expect(value.toFromNow()).toBe(expected);
}); });
@ -262,7 +262,7 @@ describe('DateTime', () => {
it('should format to from now string', () => { it('should format to from now string', () => {
const value = DateTime.now().addMinutes(-4); const value = DateTime.now().addMinutes(-4);
const expected = '4 minuti'; const expected = '4 minuti fa';
expect(value.toFromNow()).toBe(expected); expect(value.toFromNow()).toBe(expected);
}); });

2
frontend/src/app/framework/utils/date-time.ts

@ -193,7 +193,7 @@ export class DateTime {
} }
public toFromNow(): string { public toFromNow(): string {
return formatDistanceToNow(this.value, { locale: DateHelper.getFnsLocale() }); return formatDistanceToNow(this.value, { locale: DateHelper.getFnsLocale(), addSuffix: true });
} }
public toISOString(withoutMilliseconds = true): string { public toISOString(withoutMilliseconds = true): string {

Loading…
Cancel
Save