Commit 83064c25 authored by yangxiaodong's avatar yangxiaodong

modify job processor executor step.

parent ea2cf5f9
......@@ -81,37 +81,35 @@ namespace DotNetCore.CAP.RabbitMQ
{
var provider = scopedContext.Provider;
var messageStore = provider.GetRequiredService<ICapMessageStore>();
var message = await messageStore.GetNextSentMessageToBeEnqueuedAsync();
try
{
var message = await messageStore.GetNextSentMessageToBeEnqueuedAsync();
if (message != null)
{
var sp = Stopwatch.StartNew();
message.StatusName = StatusName.Processing;
await messageStore.UpdateSentMessageAsync(message);
var jobResult = ExecuteJob(message.KeyName, message.Content);
ExecuteJob(message.KeyName, message.Content);
sp.Stop();
if (jobResult)
{
await messageStore.RemoveSentMessageAsync(message);
message.StatusName = StatusName.Succeeded;
await messageStore.UpdateSentMessageAsync(message);
_logger.JobExecuted(sp.Elapsed.TotalSeconds);
}
}
}
catch (Exception)
catch (Exception ex)
{
_logger.ExceptionOccuredWhileExecutingJob(message.KeyName, ex);
return false;
}
}
return true;
}
private bool ExecuteJob(string topic, string content)
{
try
private void ExecuteJob(string topic, string content)
{
var factory = new ConnectionFactory()
{
......@@ -135,14 +133,6 @@ namespace DotNetCore.CAP.RabbitMQ
routingKey: topic,
basicProperties: null,
body: body);
return true;
}
}
catch (Exception ex)
{
_logger.ExceptionOccuredWhileExecutingJob(topic, ex);
return false;
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment