/// <inheritdoc /> public async Task MarkOrphanedEventsErrored(EventWorker orphanedWorker) { // Read the event locks which each have an event id var orphanedEventLocks = await this.eventLockRepository.ReadByWorker(orphanedWorker); var loggingTask = orphanedEventLocks .Select(e => this.logger.LogVerboseAsync($"Orphaned events found from event locks: {e.EventId} from worker: {orphanedWorker.Id} - {orphanedWorker.Name}")) .WhenAllStreamed(); // Get the event ids and read the events var orphanedEvents = await orphanedEventLocks .DistinctBy(l => l.EventId) .Select(l => this.eventRepository.ReadAsync(l.EventId)) .WhenAllStreamed(); // mark the event status errored and commit var updateTask = orphanedEvents .ForEach(e => e.Status = EventStatus.Error) .Select(e => this.eventRepository.UpdateAsync(e)) .WhenAllStreamed(); // Release all the locks for the worker var lockReleaseTask = this.eventLockRepository.Release(orphanedWorker); await Task.WhenAll(loggingTask, updateTask, lockReleaseTask); }
private void _onExampleCommand(ExampleCommand cmd) { // this checks the aggregate to see if a user with this Id has already been created if (_Id != null) { throw new ArgumentException("Id", "User already created"); } // here is where we can ensure that the command has all the information in it that we expect it to have if (cmd.Id == null) { throw new ArgumentException("Id", "Id is a required field"); } if (cmd.Email == null) { throw new ArgumentException("Email", "Email is a required field"); } if (cmd.Name == null) { throw new ArgumentException("Name", "Name is a required field"); } // now we assign values to the event model that we created in ExampleEvent Thread.Sleep(100); ExampleEvent exampleEvent = new ExampleEvent { Id = cmd.Id, Name = cmd.Name, Email = cmd.Email }; // And finally we send the example event off to the Event Worker to be saved, filed and published EventWorker.Work(exampleEvent); }
public async Task MarkOrphanedEventsErrored() { // Arrange var worker = new EventWorker { Id = 234 }; var eventLocks = new[] { new EventLock { EventId = 333 }, new EventLock { EventId = 444 } }; this.eventLockRepository.Setup(r => r.ReadByWorker(It.IsAny <EventWorker>())) .ReturnsAsync(eventLocks); this.eventRepository.Setup(r => r.ReadAsync(It.IsAny <long>())) .ReturnsAsync(new Event { Status = EventStatus.InProgress }); this.eventRepository.Setup(r => r.UpdateAsync(It.IsAny <Event>())) .Returns(Task.Delay(1)); this.eventLockRepository.Setup(r => r.Release(It.IsAny <EventWorker>())).Returns(Task.Delay(1)); // Act await this.eventOrphanService.MarkOrphanedEventsErrored(worker); // Assert this.eventRepository.Verify(r => r.UpdateAsync(It.Is <Event>(e => e.Status == EventStatus.Error)), Times.Exactly(eventLocks.Length)); this.eventLockRepository.Verify(r => r.Release(It.IsAny <EventWorker>())); }
public async Task Execute(CancellationToken cancellationToken, EventWorker eventWorker = null) { cancellationToken.ThrowIfCancellationRequested(); DataSetup.Setup(); this.queuingConfiguration.ConfigureSystem(); var worker = await this.eventWorkerService.CreateWorker(eventWorker); // Mark any events and event locks as orphaned since we haven't started processing anything yet. await this.eventOrphanService.MarkOrphanedEventsErrored(worker); await this.logger.LogVerboseAsync( $"Starting Job Server on Event Worker Id: {worker?.Id} - Name: {worker?.Name}"); using (var server = this.kernel.Get <IJobServer>()) { await server.WaitTillProcessesAreDone(cancellationToken); await this.logger.LogVerboseAsync( $"Processes done, begin jobServer dispose on Event Worker Id: {worker?.Id} - Name: {worker?.Name}"); } await this.logger.LogVerboseAsync( $"Job Server disposed on Event Worker Id: {worker?.Id} - Name: {worker?.Name}"); await this.eventWorkerService.RemoveCurrentWorker(); await this.logger.LogVerboseAsync( $"Removed Event Worker Id: {worker?.Id} - Name: {worker?.Name}"); }
/// <inheritdoc /> public async Task <IList <EventLock> > ReadByWorker(EventWorker eventWorker) { using (var conn = this.connectionFactory.GetEddsPerformanceConnection()) { return((await conn.QueryAsync <EventLock>(Resources.EventLock_ReadByWorker, new { workerId = eventWorker.Id })).ToList()); } }
/// <inheritdoc /> public async Task Release(EventWorker eventWorker) { using (var conn = this.connectionFactory.GetEddsPerformanceConnection()) { await conn.ExecuteAsync(Resources.EventLock_ReleaseByWorker, new { workerId = eventWorker.Id }); } }
public async Task DeleteAsync(EventWorker eventWorker) { using (var conn = connectionFactory.GetEddsPerformanceConnection()) { await conn.ExecuteAsync(Resources.EventWorker_Delete, new { eventWorker.Id }); } }
public Editor() { forcePause = true; doCloseButton = false; _itemWorker = new ItemWorker(); _pawnWorker = new PawnWorker(); _eventWorker = new EventWorker(); _traitWorker = new TraitWorker(); }
public async Task SetUp() { this.testLocks = new List <EventLock>(); this.eventLockRepository = new EventLockRepository(ConnectionFactorySetup.ConnectionFactory); this.eventWorkerRepository = new EventWorkerRepository(ConnectionFactorySetup.ConnectionFactory); var worker = new EventWorker { Id = 1234588, Name = "Delete me. Create from tests", Type = EventWorkerType.Other }; this.eventWorker = await this.eventWorkerRepository.CreateAsync(worker); }
public async Task <EventWorker> CreateAsync(EventWorker eventWorker) { using (var conn = connectionFactory.GetEddsPerformanceConnection()) { var updateRecords = await conn.ExecuteAsync(Resources.EventWorker_Update, eventWorker); if (updateRecords == 0) { await conn.ExecuteAsync(Resources.EventWorker_Create, eventWorker); } return(await conn.QueryFirstOrDefaultAsync <EventWorker>(Resources.EventWorker_Read, new{ eventWorker.Id })); } }
/// <summary> /// Initializes a new instance of the <see cref="MainWindow"/> class. /// </summary> public MainWindow() { Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; InitializeComponent(); LogoText.Text = @" ____ _ ____ _____________ ____ / __ \(_)____ / __ )____ __ __ < / ____/ __ \/ __ \ / /_/ / / ___/_____/ __ / __ \/ / / /_____/ /___ \/ / / / / / / / ____/ / /__/_____/ /_/ / /_/ / /_/ /_____/ /___/ / /_/ / /_/ / /_/ /_/\___/ /_____/\____/\__, / /_/_____/\____/\____/ /____/ "; EventWorker = new EventWorker(); Events = new ObservableCollection <Event>(EventWorker.GetAll()); EventList.ItemsSource = Events; }
public async Task Event_Worker_CreateReadAndDelete() { var id = 1234588; var worker = new EventWorker { Id = id, Name = "Delete me. Create from tests", Type = (EventWorkerType)1234 }; // using dummy Type value for testing var createResult = await repository.CreateAsync(worker); var readAllResult = await repository.ReadAllWorkersAsync(); await repository.DeleteAsync(createResult); // Assert Assert.That(createResult, Is.Not.Null); Assert.That(createResult.Id, Is.EqualTo(id)); Assert.That((int)createResult.Type, Is.EqualTo(1234)); Assert.That(readAllResult, Is.Not.Empty); Assert.That(readAllResult.Any(r => r.Id == id), Is.True); }
/// <summary> /// Initializes a new instance of the <see cref="ManageEvent"/> class. /// </summary> /// <param name="events">Observable collection of events to work with.</param> public ManageEvent(ObservableCollection <Event> events) { Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; Events = events; EventWorker = new EventWorker(); InitializeComponent(); var currentTime = DateTime.Now; currentTime = currentTime.AddMilliseconds(-currentTime.Millisecond); if (ManagedEvent == null) { ManagedEvent = new Event { Name = "", DateBegin = currentTime.AddMinutes(15), DateEnd = currentTime.EndOfDay() }; } }
public EventController(DataFactory dataFactory) { _eventWorker = (EventWorker)dataFactory.GetDataFactory <Event>(); }
public Task <EventWorker> CreateWorker(EventWorker worker = null) => this.eventWorkerRepository.CreateAsync(worker ?? new EventWorker(this.agentService));