Commit 83064c25 authored by yangxiaodong's avatar yangxiaodong

modify job processor executor step.

parent ea2cf5f9
...@@ -81,37 +81,35 @@ namespace DotNetCore.CAP.RabbitMQ ...@@ -81,37 +81,35 @@ namespace DotNetCore.CAP.RabbitMQ
{ {
var provider = scopedContext.Provider; var provider = scopedContext.Provider;
var messageStore = provider.GetRequiredService<ICapMessageStore>(); var messageStore = provider.GetRequiredService<ICapMessageStore>();
var message = await messageStore.GetNextSentMessageToBeEnqueuedAsync();
try try
{ {
var message = await messageStore.GetNextSentMessageToBeEnqueuedAsync();
if (message != null) if (message != null)
{ {
var sp = Stopwatch.StartNew(); var sp = Stopwatch.StartNew();
message.StatusName = StatusName.Processing; message.StatusName = StatusName.Processing;
await messageStore.UpdateSentMessageAsync(message); await messageStore.UpdateSentMessageAsync(message);
var jobResult = ExecuteJob(message.KeyName, message.Content); ExecuteJob(message.KeyName, message.Content);
sp.Stop(); sp.Stop();
if (jobResult) message.StatusName = StatusName.Succeeded;
{ await messageStore.UpdateSentMessageAsync(message);
await messageStore.RemoveSentMessageAsync(message);
_logger.JobExecuted(sp.Elapsed.TotalSeconds); _logger.JobExecuted(sp.Elapsed.TotalSeconds);
} }
} }
} catch (Exception ex)
catch (Exception)
{ {
_logger.ExceptionOccuredWhileExecutingJob(message.KeyName, ex);
return false; return false;
} }
} }
return true; return true;
} }
private bool ExecuteJob(string topic, string content) private void ExecuteJob(string topic, string content)
{
try
{ {
var factory = new ConnectionFactory() var factory = new ConnectionFactory()
{ {
...@@ -135,14 +133,6 @@ namespace DotNetCore.CAP.RabbitMQ ...@@ -135,14 +133,6 @@ namespace DotNetCore.CAP.RabbitMQ
routingKey: topic, routingKey: topic,
basicProperties: null, basicProperties: null,
body: body); 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