public async Task Post(PushWebHookEvent e) { Trace.TraceInformation($"CommitPushed Started: {e}"); try { if (e.Commits != null) { foreach (Commit c in e.Commits) { if (c.modified != null) { foreach (string modified in c.modified) { ModifiedFileModel modifiedFile; if (!ModifiedFileModel.TryParse(e.Repository.Full_Name, e.Ref, modified, out modifiedFile)) { Trace.TraceWarning($"Skipping file '{modified}'"); continue; } List <Task> handlerTasks = new List <Task>(); foreach (ISubscriptionHandler handler in await _eventService.GetSubscriptionHandlers(modifiedFile)) { if (handler.Delay.HasValue) { DelayedMessage message = new DelayedMessage(); message.HandlerType = handler.GetType().AssemblyQualifiedName; message.HandlerData = JsonConvert.SerializeObject(handler); handlerTasks.Add( _storageService.EnqueueMessage( DelayedMessage.QueueName, JsonConvert.SerializeObject(message), handler.Delay)); } else { handlerTasks.Add(handler.Execute()); } } await Task.WhenAll(handlerTasks); } } } } } catch (Exception ex) { Trace.TraceError($"An unhandled exception occurred handling PushWebHookEvent {e} : Exception: {ex}"); throw; } Trace.TraceInformation("CommitPushed Complete"); }
public async Task Post(PushWebHookEvent e) { Trace.TraceInformation($"CommitPushed Started: {e}"); try { if (e.Commits != null) { SubscriptionsModel subscriptionsModel = await SubscriptionsModel.CreateAsync(); // only invoke a specific handler once per a push notification HashSet <ISubscriptionHandler> handlers = new HashSet <ISubscriptionHandler>(); foreach (Commit c in e.Commits) { foreach (string changedFilePath in c.GetAllChangedFiles()) { ModifiedFileModel modifiedFile; if (!ModifiedFileModel.TryParse(e.Repository.Full_Name, e.Ref, changedFilePath, c, out modifiedFile)) { Trace.TraceWarning($"Skipping file '{changedFilePath}'"); continue; } foreach (ISubscriptionHandler handler in subscriptionsModel.GetHandlers(modifiedFile)) { handlers.Add(handler); } } } List <Task> handlerTasks = new List <Task>(); foreach (ISubscriptionHandler handler in handlers) { if (handler.Delay.HasValue) { DelayedMessage message = new DelayedMessage(); message.HandlerType = handler.GetType().AssemblyQualifiedName; message.HandlerData = JsonConvert.SerializeObject(handler); handlerTasks.Add( _storageService.EnqueueMessage( DelayedMessage.QueueName, JsonConvert.SerializeObject(message), handler.Delay)); } else { handlerTasks.Add(handler.Execute()); } } await Task.WhenAll(handlerTasks); } } catch (Exception ex) { Trace.TraceError($"An unhandled exception occurred handling PushWebHookEvent {e} : Exception: {ex}"); throw; } Trace.TraceInformation("CommitPushed Complete"); }