Example #1
0
    public virtual async Task EnqueueAsync(IncomingEventInfo incomingEvent)
    {
        var dbContext = await DbContextProvider.GetDbContextAsync();

        dbContext.IncomingEvents.Add(
            new IncomingEventRecord(incomingEvent)
            );
    }
    public override async Task MarkAsProcessedAsync(Guid id)
    {
        var dbContext = await DbContextProvider.GetDbContextAsync();

        var tableName = dbContext.IncomingEvents.EntityType.GetSchemaQualifiedTableName();

        var sql = $"UPDATE {tableName} SET Processed = '1', ProcessedTime = '{Clock.Now}' WHERE Id = '{id.ToString().ToUpper()}'";
        await dbContext.Database.ExecuteSqlRawAsync(sql);
    }
    public override async Task DeleteAsync(Guid id)
    {
        var dbContext = (IHasEventOutbox)await DbContextProvider.GetDbContextAsync();

        var tableName = dbContext.OutgoingEvents.EntityType.GetSchemaQualifiedTableName();

        var sql = $"DELETE FROM \"{tableName}\" WHERE \"Id\" = '{id}'";
        await dbContext.Database.ExecuteSqlRawAsync(sql);
    }
Example #4
0
    public override async Task MarkAsProcessedAsync(Guid id)
    {
        var dbContext = await DbContextProvider.GetDbContextAsync();

        var tableName = dbContext.IncomingEvents.EntityType.GetSchemaQualifiedTableName();

        var sql = $"UPDATE \"{tableName}\" SET \"Processed\" = '1', \"ProcessedTime\" = TO_DATE('{Clock.Now}', 'yyyy-mm-dd hh24:mi:ss') WHERE \"Id\" = HEXTORAW('{GuidToOracleType(id)}')";
        await dbContext.Database.ExecuteSqlRawAsync(sql);
    }
    public override async Task MarkAsProcessedAsync(Guid id)
    {
        var dbContext = await DbContextProvider.GetDbContextAsync();

        var tableName = dbContext.IncomingEvents.EntityType.GetSchemaQualifiedTableName();

        var sql = $"UPDATE \"{tableName}\" SET \"Processed\" = '1', \"ProcessedTime\" = '{Clock.Now}' WHERE \"Id\" = '{id}'";
        await dbContext.Database.ExecuteSqlRawAsync(sql);
    }
    public override async Task DeleteOldEventsAsync()
    {
        var dbContext = await DbContextProvider.GetDbContextAsync();

        var tableName        = dbContext.IncomingEvents.EntityType.GetSchemaQualifiedTableName();
        var timeToKeepEvents = Clock.Now - EventBusBoxesOptions.WaitTimeToDeleteProcessedInboxEvents;

        var sql = $"DELETE FROM {tableName} WHERE Processed = '1' AND CreationTime < '{timeToKeepEvents}'";
        await dbContext.Database.ExecuteSqlRawAsync(sql);
    }
Example #7
0
    public override async Task DeleteOldEventsAsync()
    {
        var dbContext = await DbContextProvider.GetDbContextAsync();

        var tableName        = dbContext.IncomingEvents.EntityType.GetSchemaQualifiedTableName();
        var timeToKeepEvents = Clock.Now - EventBusBoxesOptions.WaitTimeToDeleteProcessedInboxEvents;

        var sql = $"DELETE FROM \"{tableName}\" WHERE \"Processed\" = '1' AND \"CreationTime\" < TO_DATE('{timeToKeepEvents}', 'yyyy-mm-dd hh24:mi:ss')";
        await dbContext.Database.ExecuteSqlRawAsync(sql);
    }
Example #8
0
    public virtual async Task DeleteOldEventsAsync()
    {
        var dbContext = await DbContextProvider.GetDbContextAsync();

        var timeToKeepEvents = Clock.Now - EventBusBoxesOptions.WaitTimeToDeleteProcessedInboxEvents;
        var oldEvents        = await dbContext.IncomingEvents
                               .Where(x => x.Processed && x.CreationTime < timeToKeepEvents)
                               .ToListAsync();

        dbContext.IncomingEvents.RemoveRange(oldEvents);
    }
Example #9
0
    public virtual async Task MarkAsProcessedAsync(Guid id)
    {
        var dbContext = await DbContextProvider.GetDbContextAsync();

        var incomingEvent = await dbContext.IncomingEvents.FindAsync(id);

        if (incomingEvent != null)
        {
            incomingEvent.MarkAsProcessed(Clock.Now);
        }
    }
Example #10
0
        protected Task <TMongoDbContext> GetDbContextAsync(CancellationToken cancellationToken = default)
        {
            // Multi-tenancy unaware entities should always use the host connection string
            if (!EntityHelper.IsMultiTenant <TEntity>())
            {
                using (CurrentTenant.Change(null))
                {
                    return(DbContextProvider.GetDbContextAsync(GetCancellationToken(cancellationToken)));
                }
            }

            return(DbContextProvider.GetDbContextAsync(GetCancellationToken(cancellationToken)));
        }
Example #11
0
    public virtual async Task DeleteOldEventsAsync()
    {
        var dbContext = await DbContextProvider.GetDbContextAsync();

        var timeToKeepEvents = Clock.Now - EventBusBoxesOptions.WaitTimeToDeleteProcessedInboxEvents;

        if (dbContext.SessionHandle != null)
        {
            await dbContext.IncomingEvents.DeleteManyAsync(dbContext.SessionHandle, x => x.Processed && x.CreationTime < timeToKeepEvents);
        }
        else
        {
            await dbContext.IncomingEvents.DeleteManyAsync(x => x.Processed && x.CreationTime < timeToKeepEvents);
        }
    }
Example #12
0
    public virtual async Task <List <IncomingEventInfo> > GetWaitingEventsAsync(int maxCount, CancellationToken cancellationToken = default)
    {
        var dbContext = await DbContextProvider.GetDbContextAsync();

        var outgoingEventRecords = await dbContext
                                   .IncomingEvents
                                   .AsNoTracking()
                                   .Where(x => !x.Processed)
                                   .OrderBy(x => x.CreationTime)
                                   .Take(maxCount)
                                   .ToListAsync(cancellationToken: cancellationToken);

        return(outgoingEventRecords
               .Select(x => x.ToIncomingEventInfo())
               .ToList());
    }
Example #13
0
    public virtual async Task MarkAsProcessedAsync(Guid id)
    {
        var dbContext = await DbContextProvider.GetDbContextAsync();

        var filter = Builders <IncomingEventRecord> .Filter.Eq(x => x.Id, id);

        var update = Builders <IncomingEventRecord> .Update.Set(x => x.Processed, true).Set(x => x.ProcessedTime, Clock.Now);

        if (dbContext.SessionHandle != null)
        {
            await dbContext.IncomingEvents.UpdateOneAsync(dbContext.SessionHandle, filter, update);
        }
        else
        {
            await dbContext.IncomingEvents.UpdateOneAsync(filter, update);
        }
    }
Example #14
0
    public virtual async Task EnqueueAsync(IncomingEventInfo incomingEvent)
    {
        var dbContext = await DbContextProvider.GetDbContextAsync();

        if (dbContext.SessionHandle != null)
        {
            await dbContext.IncomingEvents.InsertOneAsync(
                dbContext.SessionHandle,
                new IncomingEventRecord(incomingEvent)
                );
        }
        else
        {
            await dbContext.IncomingEvents.InsertOneAsync(
                new IncomingEventRecord(incomingEvent)
                );
        }
    }
Example #15
0
 protected Task <TMongoDbContext> GetDbContextAsync(CancellationToken cancellationToken = default)
 {
     return(DbContextProvider.GetDbContextAsync(GetCancellationToken(cancellationToken)));
 }
Example #16
0
    public virtual async Task <bool> ExistsByMessageIdAsync(string messageId)
    {
        var dbContext = await DbContextProvider.GetDbContextAsync();

        return(await dbContext.IncomingEvents.AnyAsync(x => x.MessageId == messageId));
    }