Пример #1
0
        public async Task Run()
        {
            var events = await HangfireQueue.GetEvents("OnUserCreateCreateQuery");

            var handledEvents = new List <EventAndJob>();
            var enumerator    = events.GetEnumerator();

            for (
                ; enumerator.MoveNext();
                )
            {
                var eventWrapper = enumerator.Current;
                var domainEvent  = (UserCreateEvent)eventWrapper.DomainEvent;
                var entity       = await UserRepository.GetUser(domainEvent.Id);

                var newCreateEvent = new UserCreateEvent(entity, domainEvent.EntityId);
                var hookResult     = await AsyncHook.Execute(newCreateEvent);

                if (hookResult.Ok)
                {
                    handledEvents.Add(eventWrapper);
                }
            }
            await HangfireQueue.RemoveEventsFromQueue(handledEvents);
        }
Пример #2
0
        public async Task Run()
        {
            var events = await HangfireQueue.GetEvents("SendBirthdayMail");

            var handledEvents = new List <EventAndJob>();
            var enumerator    = events.GetEnumerator();

            for (
                ; enumerator.MoveNext();
                )
            {
                var eventWrapper = enumerator.Current;
                var domainEvent  = (UserUpdateAgeEvent)eventWrapper.DomainEvent;
                var hookResult   = await AsyncHook.Execute(domainEvent);

                if (hookResult.Ok)
                {
                    handledEvents.Add(eventWrapper);
                }
            }
            await HangfireQueue.RemoveEventsFromQueue(handledEvents);
        }