public Task WhenWeRefreshLevyData() { var timeout = Debugger.IsAttached ? 10 * 60 * 1000 : StepTimeout; var cancellationTokenSource = new CancellationTokenSource(timeout); var account = _objectContext.Get <Account>(); _objectContainer.Resolve <ILog>().Info("About to start levy run task."); return(_objectContainer.RunStepsInIsolation(cancellationTokenSource.Token, // step 1: send request to get levy declarations to start that process running... c => { _objectContainer.Resolve <ILog>().Info("About to start levy run."); var empref = _objectContext.GetEmpRef(); return c.Resolve <IMessageSession>().Send(new ImportAccountLevyDeclarationsCommand ( account.Id, empref )); }, // step 2: wait for the levy declaration process to finish writing the transactions... async c => { _objectContainer.Resolve <ILog>().Info("About to start polling for levy decalaration."); var allLevyDeclarationsLoaded = await c.Resolve <ITransactionRepository>() .WaitForAllTransactionLinesInDatabase(account, cancellationTokenSource.Token); if (!allLevyDeclarationsLoaded) { throw new Exception($"The levy declarations have not been completely loaded within the allowed time ({timeout} msecs). Either they are still loading or something has failed."); } })); }