private async Task StashUnpublishedEvents() { if (!_shutdown) { var pub = await QueueProvider.DequeueForPublishing(); while (pub != null) { await PersistenceStore.CreateUnpublishedEvent(pub); pub = await QueueProvider.DequeueForPublishing(); } } }
private void RunPublications() { IPersistenceProvider persistenceStore = _serviceProvider.GetService <IPersistenceProvider>(); while (!_shutdown) { try { var pub = QueueProvider.DequeueForPublishing().Result; if (pub != null) { try { if (LockProvider.AcquireLock(pub.WorkflowId).Result) { try { var workflow = persistenceStore.GetWorkflowInstance(pub.WorkflowId).Result; var pointers = workflow.ExecutionPointers.Where(p => p.EventName == pub.EventName && p.EventKey == p.EventKey && !p.EventPublished); foreach (var p in pointers) { p.EventData = pub.EventData; p.EventPublished = true; p.Active = true; } workflow.NextExecution = 0; persistenceStore.PersistWorkflow(workflow); } catch (Exception ex) { Logger.LogError(ex.Message); persistenceStore.CreateUnpublishedEvent(pub); //retry later } finally { LockProvider.ReleaseLock(pub.WorkflowId).Wait(); QueueProvider.QueueForProcessing(pub.WorkflowId); } } else { Logger.LogInformation("Workflow locked {0}", pub.WorkflowId); persistenceStore.CreateUnpublishedEvent(pub); //retry later } } catch (Exception ex) { Logger.LogError(ex.Message); } } else { Thread.Sleep(Options.IdleTime); //no work } } catch (Exception ex) { Logger.LogError(ex.Message); } } }