/// <summary> /// It is called dynamically. /// </summary> public async Task Execute(CancellationToken cancellationToken, AutoBook autoBook) { try { try { _autoBooks.Create(autoBook); _auditEventRepository.Insert(AuditEventFactory.CreateAuditEventForInformationMessage(0, 0, $"Creating AutoBook instance (AutoBookID={autoBook.Id}): Waiting for Idle notification")); } catch (Exception ex) { _auditEventRepository.Insert(AuditEventFactory.CreateAuditEventForException(0, 0, $"Error creating AutoBook (AutoBookID={autoBook.Id})", ex)); autoBook.Status = AutoBookStatuses.Fatal_Error; _autoBookRepository.Update(autoBook); } } finally { foreach (var dbContext in _tenantDbContexts) { try { await dbContext.SaveChangesAsync(cancellationToken).ConfigureAwait(false); } catch //ignore exception { } } } }
/// <summary> /// Resets AutoBook to be free for re-use /// </summary> public void ResetFree() { lock (_autoBook) { _autoBook.Locked = false; _autoBook.Task = null; _autoBookRepository.Update(_autoBook); } }