Example #1
0
        public static async Task Go(DbConnection connection, EventQueueItem item, IServiceProvider provider, DbTransaction transaction)
        {
            var      type     = Type.GetType(item.Action);
            BaseTask resolved = null;

            try
            {
                if (type != null)
                {
                    resolved = (BaseTask)ActivatorUtilities.CreateInstance(provider, type, item);
                    await resolved.Go();
                }

                await connection.ExecuteAsync("DELETE from \"EventQueue\" where \"Id\" = @Id", new { Id = item.Id });

                transaction.Commit();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                // failed
                item.AttemptCount++;
                item.NextAttempt = resolved.NextTry(item.AttemptCount);

                transaction.Rollback();
                await connection.ExecuteAsync("UPDATE \"EventQueue\" set \"AttemptCount\"=@AttemptCount, \"NextAttempt\"=@NextAttempt where \"Id\" = @Id", new { Attemptcount = item.AttemptCount, NextAttempt = item.NextAttempt, Id = item.Id });
            }

            transaction.Dispose();
        }
 private void HandleEventInsert(TAggregate aggregateRoot, SqlConnection con, SqlTransaction tran)
 {
     foreach (var evnt in aggregateRoot.UncommittedChanges())
     {
         var eventData = EventQueueItem.Serialize(evnt, typeof(TAggregate).Name, Guid.NewGuid());
         con.Execute($"insert into [Messaging].[EventQueue] values ('{eventData.AggregateRootId}','{eventData.CorrelationId}','{eventData.EventName}','{eventData.OccuredOn}','{eventData.Payload}','{eventData.AggregateName}')", transaction: tran);
     }
 }
Example #3
0
 public DeliverToActivityPubTask(EventQueueItem item, IEntityStore entityStore, EntityFlattener entityFlattener, IServiceProvider serviceProvider, DeliveryService deliveryService, APContext context, EntityData data) : base(item)
 {
     _entityStore     = entityStore;
     _entityFlattener = entityFlattener;
     _serviceProvider = serviceProvider;
     _deliveryService = deliveryService;
     _context         = context;
     _data            = data;
 }
Example #4
0
 public DeliverToActivityPubTask(EventQueueItem item, IEntityStore entityStore, EntityFlattener entityFlattener, IServiceProvider serviceProvider, DeliveryService deliveryService, SignatureVerifier verifier, KeyService keyService) : base(item)
 {
     _entityStore     = entityStore;
     _entityFlattener = entityFlattener;
     _serviceProvider = serviceProvider;
     _deliveryService = deliveryService;
     _verifier        = verifier;
     _keyService      = keyService;
 }
Example #5
0
 public static Data.EventQueueItem ToXferData(this EventQueueItem item)
 {
     return(new Data.EventQueueItem
     {
         UserId = item.User.Id,
         StartTime = item.StartTime,
         EndTime = item.EndTime,
         RandomlySelected = item.RandomlySelected,
     });
 }
Example #6
0
        public static async Task Go(APContext context, EventQueueItem item, IServiceProvider provider)
        {
            var type = Type.GetType("Kroeg.Server.BackgroundTasks." + item.Action);

            var resolved = (BaseTask)ActivatorUtilities.CreateInstance(provider, type, item);

            try
            {
                await resolved.Go();

                context.EventQueue.Remove(item);
            }
            catch (Exception)
            {
                // failed
                item.AttemptCount++;
                item.NextAttempt = resolved.NextTry(item.AttemptCount);
            }

            await context.SaveChangesAsync();
        }
Example #7
0
        private async Task ProcessEventQueue(IThreadLoopEvent loopEvent)
        {
            while (true)
            {
                EventQueueItem item = null;

                var didDequeue = _queue.TryDequeue(out item);

                if (!didDequeue)
                {
                    return;
                }

                FireEvent(item.Event);

                if (loopEvent.IsCancelled)
                {
                    break;
                }
            }

            await Task.CompletedTask;
        }
Example #8
0
 public DeliverToWebSubTask(EventQueueItem item, IEntityStore entityStore, AtomEntryGenerator entryGenerator, DbConnection connection) : base(item)
 {
     _entityStore    = entityStore;
     _entryGenerator = entryGenerator;
     _connection     = connection;
 }
Example #9
0
 protected BaseTask(EventQueueItem item)
 {
     EventQueueItem = item;
 }
Example #10
0
 public GetEntityTask(EventQueueItem item, IEntityStore entityStore) : base(item)
 {
     _entityStore = entityStore;
 }
Example #11
0
 public WebSubBackgroundTask(EventQueueItem item, IEntityStore entityStore, APContext context, CollectionTools collectionTools) : base(item)
 {
     _entityStore     = entityStore;
     _context         = context;
     _collectionTools = collectionTools;
 }
Example #12
0
 public WebSubBackgroundTask(EventQueueItem item, IEntityStore entityStore, DbConnection connection, CollectionTools collectionTools) : base(item)
 {
     _entityStore     = entityStore;
     _connection      = connection;
     _collectionTools = collectionTools;
 }
Example #13
0
 public DeliverToSalmonTask(EventQueueItem item, IEntityStore entityStore, AtomEntryGenerator entryGenerator, KeyService keyService) : base(item)
 {
     _entityStore    = entityStore;
     _entryGenerator = entryGenerator;
     _keyService     = keyService;
 }
Example #14
0
 public DeliverToSalmonTask(EventQueueItem item, IEntityStore entityStore, APContext context, AtomEntryGenerator entryGenerator) : base(item)
 {
     _entityStore    = entityStore;
     _context        = context;
     _entryGenerator = entryGenerator;
 }