private async Task <bool> Step(ProcessingContext context) { using (var scopedContext = context.CreateScope()) { var provider = scopedContext.Provider; var messageStore = provider.GetRequiredService <ICapMessageStore>(); var message = await messageStore.GetNextSentMessageToBeEnqueuedAsync(); try { if (message != null) { var sp = Stopwatch.StartNew(); message.StatusName = StatusName.Processing; await messageStore.UpdateSentMessageAsync(message); ExecuteJob(message.KeyName, message.Content); sp.Stop(); message.StatusName = StatusName.Succeeded; await messageStore.UpdateSentMessageAsync(message); _logger.JobExecuted(sp.Elapsed.TotalSeconds); } } catch (Exception ex) { _logger.ExceptionOccuredWhileExecutingJob(message?.KeyName, ex); return(false); } } return(true); }