Browse Source

Id fix.

pull/511/head
Sebastian 6 years ago
parent
commit
25bf0de335
  1. 2
      backend/src/Squidex.Domain.Apps.Core.Model/Rules/RuleJob.cs
  2. 2
      backend/src/Squidex.Domain.Apps.Core.Operations/HandleRules/RuleService.cs
  3. 23
      backend/src/Squidex.Domain.Apps.Entities.MongoDb/Rules/MongoRuleEventRepository.cs
  4. 34
      backend/src/Squidex.Infrastructure/UniqueConstraintException.cs
  5. 2
      backend/tests/Squidex.Domain.Apps.Core.Tests/Operations/HandleRules/RuleServiceTests.cs
  6. 2
      backend/tests/Squidex.Domain.Apps.Entities.Tests/Rules/RuleDequeuerTests.cs

2
backend/src/Squidex.Domain.Apps.Core.Model/Rules/RuleJob.cs

@ -12,7 +12,7 @@ namespace Squidex.Domain.Apps.Core.Rules
{
public sealed class RuleJob
{
public Guid Id { get; set; }
public Guid EventId { get; set; }
public Guid AppId { get; set; }

2
backend/src/Squidex.Domain.Apps.Core.Operations/HandleRules/RuleService.cs

@ -141,12 +141,12 @@ namespace Squidex.Domain.Apps.Core.HandleRules
var job = new RuleJob
{
Id = Guid.NewGuid(),
ActionData = json,
ActionName = actionName,
AppId = enrichedEvent.AppId.Id,
Created = now,
Description = actionData.Description,
EventId = @event.Headers.EventId(),
EventName = enrichedEvent.Name,
ExecutionPartition = enrichedEvent.Partition,
Expires = expires,

23
backend/src/Squidex.Domain.Apps.Entities.MongoDb/Rules/MongoRuleEventRepository.cs

@ -15,6 +15,7 @@ using Squidex.Domain.Apps.Core.HandleRules;
using Squidex.Domain.Apps.Core.Rules;
using Squidex.Domain.Apps.Entities.Rules;
using Squidex.Domain.Apps.Entities.Rules.Repositories;
using Squidex.Infrastructure;
using Squidex.Infrastructure.MongoDb;
using Squidex.Infrastructure.Reflection;
@ -93,11 +94,27 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Rules
return Collection.UpdateOneAsync(x => x.Id == id, Update.Set(x => x.NextAttempt, nextAttempt));
}
public Task EnqueueAsync(RuleJob job, Instant nextAttempt)
public async Task EnqueueAsync(RuleJob job, Instant nextAttempt)
{
var entity = SimpleMapper.Map(job, new MongoRuleEventEntity { Job = job, Created = nextAttempt, NextAttempt = nextAttempt });
return Collection.InsertOneIfNotExistsAsync(entity);
if (job.EventId != default)
{
entity.Id = job.EventId;
}
else
{
entity.Id = Guid.NewGuid();
}
try
{
await Collection.InsertOneIfNotExistsAsync(entity);
}
catch (MongoWriteException ex) when (ex.WriteError.Category == ServerErrorCategory.DuplicateKey)
{
throw new UniqueConstraintException();
}
}
public Task CancelAsync(Guid id)
@ -119,7 +136,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Rules
await statisticsCollection.IncrementFailed(job.AppId, job.RuleId, finished);
}
await Collection.UpdateOneAsync(x => x.Id == job.Id,
await Collection.UpdateOneAsync(x => x.Id == job.EventId,
Update
.Set(x => x.Result, result)
.Set(x => x.LastDump, dump)

34
backend/src/Squidex.Infrastructure/UniqueConstraintException.cs

@ -0,0 +1,34 @@
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschraenkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using System;
namespace Squidex.Infrastructure
{
[Serializable]
public class UniqueConstraintException : Exception
{
public UniqueConstraintException()
{
}
public UniqueConstraintException(string message)
: base(message)
{
}
public UniqueConstraintException(string message, Exception inner)
: base(message, inner)
{
}
protected UniqueConstraintException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
}

2
backend/tests/Squidex.Domain.Apps.Core.Tests/Operations/HandleRules/RuleServiceTests.cs

@ -376,7 +376,7 @@ namespace Squidex.Domain.Apps.Core.Operations.HandleRules
Assert.Equal(now, job.Created);
Assert.Equal(now.Plus(Duration.FromDays(30)), job.Expires);
Assert.NotEqual(Guid.Empty, job.Id);
Assert.NotEqual(Guid.Empty, job.EventId);
}
}
}

2
backend/tests/Squidex.Domain.Apps.Entities.Tests/Rules/RuleDequeuerTests.cs

@ -141,7 +141,7 @@ namespace Squidex.Domain.Apps.Entities.Rules
var job = new RuleJob
{
Id = id,
EventId = id,
ActionData = actionData,
ActionName = actionName,
Created = clock.GetCurrentInstant()

Loading…
Cancel
Save