Browse Source

Improve scheduler.

pull/572/head
Sebastian 5 years ago
parent
commit
5797698906
  1. 5
      backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentCollectionAll.cs
  2. 5
      backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentRepository.cs
  3. 2
      backend/src/Squidex.Domain.Apps.Entities/Contents/Commands/ChangeContentStatus.cs
  4. 2
      backend/src/Squidex.Domain.Apps.Entities/Contents/ContentDomainObject.cs
  5. 10
      backend/src/Squidex.Domain.Apps.Entities/Contents/ContentOperationContext.cs
  6. 17
      backend/src/Squidex.Domain.Apps.Entities/Contents/ContentSchedulerGrain.cs
  7. 2
      backend/src/Squidex.Domain.Apps.Entities/Contents/Repositories/IContentRepository.cs
  8. 4
      backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/ContentDomainObjectTests.cs

5
backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentCollectionAll.cs

@ -125,6 +125,11 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents
}
}
public Task ResetScheduledAsync(Guid id)
{
return Collection.UpdateOneAsync(x => x.Id == id, Update.Unset(x => x.ScheduleJob).Unset(x => x.ScheduledAt));
}
public Task<MongoContentEntity> FindAsync(Guid id)
{
return Collection.Find(x => x.Id == id).FirstOrDefaultAsync();

5
backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentRepository.cs

@ -114,6 +114,11 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents
}
}
public Task ResetScheduledAsync(Guid id)
{
return collectionAll.ResetScheduledAsync(id);
}
public Task QueryScheduledWithoutDataAsync(Instant now, Func<IContentEntity, Task> callback)
{
return collectionAll.QueryScheduledWithoutDataAsync(now, callback);

2
backend/src/Squidex.Domain.Apps.Entities/Contents/Commands/ChangeContentStatus.cs

@ -17,6 +17,6 @@ namespace Squidex.Domain.Apps.Entities.Contents.Commands
public Instant? DueTime { get; set; }
public Guid? JobId { get; set; }
public Guid? StatusJobId { get; set; }
}
}

2
backend/src/Squidex.Domain.Apps.Entities/Contents/ContentDomainObject.cs

@ -172,7 +172,7 @@ namespace Squidex.Domain.Apps.Entities.Contents
}
catch (Exception)
{
if (Snapshot.ScheduleJob != null && Snapshot.ScheduleJob.Id == c.JobId)
if (Snapshot.ScheduleJob != null && Snapshot.ScheduleJob.Id == c.StatusJobId)
{
CancelChangeStatus(c);
}

10
backend/src/Squidex.Domain.Apps.Entities/Contents/ContentOperationContext.cs

@ -55,21 +55,23 @@ namespace Squidex.Domain.Apps.Entities.Contents
public async Task LoadAsync(NamedId<Guid> appId, NamedId<Guid> schemaId, ContentCommand command, bool optimized)
{
this.command = command;
var (app, schema) = await appProvider.GetAppWithSchemaAsync(appId.Id, schemaId.Id);
if (app == null)
{
throw new InvalidOperationException($"Cannot resolve app with id {appId}.");
throw new DomainObjectNotFoundException(appId.ToString());
}
this.app = app;
if (schema == null)
{
throw new InvalidOperationException($"Cannot resolve schema with id id {schemaId}.");
throw new DomainObjectNotFoundException(schemaId.ToString());
}
this.app = app;
this.schema = schema;
this.command = command;
validationContext = new ValidationContext(appId, schemaId, schema.SchemaDef, command.ContentId).Optimized(optimized);
}

17
backend/src/Squidex.Domain.Apps.Entities/Contents/ContentSchedulerGrain.cs

@ -69,22 +69,31 @@ namespace Squidex.Domain.Apps.Entities.Contents
return contentRepository.QueryScheduledWithoutDataAsync(now, content =>
{
return Task.CompletedTask;
return Dispatch(async () =>
{
var id = content.Id;
try
{
var job = content.ScheduleJob;
if (job != null)
{
var command = new ChangeContentStatus { ContentId = content.Id, Status = job.Status, JobId = job.Id };
command.Actor = job.ScheduledBy;
var command = new ChangeContentStatus
{
Actor = job.ScheduledBy,
ContentId = id,
Status = job.Status,
StatusJobId = job.Id
};
await commandBus.PublishAsync(command);
}
}
catch (DomainObjectNotFoundException)
{
await contentRepository.ResetScheduledAsync(content.Id);
}
catch (Exception ex)
{
log.LogError(ex, content.Id.ToString(), (logContentId, w) => w

2
backend/src/Squidex.Domain.Apps.Entities/Contents/Repositories/IContentRepository.cs

@ -30,6 +30,8 @@ namespace Squidex.Domain.Apps.Entities.Contents.Repositories
Task<IContentEntity?> FindContentAsync(IAppEntity app, ISchemaEntity schema, Guid id, SearchScope scope);
Task ResetScheduledAsync(Guid contentId);
Task QueryScheduledWithoutDataAsync(Instant now, Func<IContentEntity, Task> callback);
}
}

4
backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/ContentDomainObjectTests.cs

@ -436,7 +436,7 @@ namespace Squidex.Domain.Apps.Entities.Contents
await ExecuteCreateAsync();
await ExecuteChangeStatusAsync(Status.Archived, dueTime);
var command = new ChangeContentStatus { Status = Status.Archived, JobId = sut.Snapshot.ScheduleJob!.Id };
var command = new ChangeContentStatus { Status = Status.Archived, StatusJobId = sut.Snapshot.ScheduleJob!.Id };
A.CallTo(() => contentWorkflow.CanMoveToAsync(A<IContentEntity>._, Status.Draft, Status.Archived, User))
.Returns(true);
@ -464,7 +464,7 @@ namespace Squidex.Domain.Apps.Entities.Contents
await ExecuteCreateAsync();
await ExecuteChangeStatusAsync(Status.Published, dueTime);
var command = new ChangeContentStatus { Status = Status.Published, JobId = sut.Snapshot.ScheduleJob!.Id };
var command = new ChangeContentStatus { Status = Status.Published, StatusJobId = sut.Snapshot.ScheduleJob!.Id };
A.CallTo(() => contentWorkflow.CanMoveToAsync(A<IContentEntity>._, Status.Draft, Status.Published, User))
.Returns(false);

Loading…
Cancel
Save