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); }
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(); }
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); }