Пример #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
        protected void InvokeContextHooks()
        {
            // context-level

            if (Hook != null && AsyncHook != null)
            {
                throw new AsyncMismatchException(
                          $"A single context cannot set both a '{hookName}' and an '{asyncHookName}', please pick one of the two");
            }

            if (Hook != null && Hook.IsAsync())
            {
                throw new AsyncMismatchException(
                          $"'{hookName}' cannot be set to an async delegate, please use '{asyncHookName}' instead");
            }

            Hook.SafeInvoke();

            AsyncHook.SafeInvoke();
        }
Пример #3
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);
        }