Add count to repeat

This commit is contained in:
luosheng
2023-07-15 22:56:59 +08:00
parent 96a8b21ae4
commit c522561fe6
3 changed files with 12 additions and 4 deletions

View File

@@ -13,13 +13,17 @@ namespace Modbus.Net
/// </summary>
public class JobChainingJobLIstenerWithDataMapRepeated : JobChainingJobListenerWithDataMap
{
protected int RepeatCount { get; set; }
/// <summary>
/// JobChaningJobListener with DataMap passing from parent job to next job
/// </summary>
/// <param name="name">Job name</param>
/// <param name="overwriteKeys">If key is overwritable, parent job will pass the value to next job event next job contains that key</param>
public JobChainingJobLIstenerWithDataMapRepeated(string name, ICollection<string> overwriteKeys) : base(name, overwriteKeys)
/// <param name="repeatCount">Repeatation count for job chain</param>
public JobChainingJobLIstenerWithDataMapRepeated(string name, ICollection<string> overwriteKeys, int repeatCount) : base(name, overwriteKeys)
{
RepeatCount = repeatCount;
}
#nullable enable
@@ -29,6 +33,7 @@ namespace Modbus.Net
CancellationToken cancellationToken = default)
{
await base.JobWasExecuted(context, jobException, cancellationToken);
if (RepeatCount == 0) return;
ChainLinks.TryGetValue(context.JobDetail.Key, out var sj);
if (sj == null)
{
@@ -39,7 +44,10 @@ namespace Modbus.Net
chainRoot = chainParent;
chainParent = ChainLinks.FirstOrDefault(p => p.Value == chainParent).Key;
}
if (RepeatCount > 0)
{
RepeatCount--;
}
var sjJobDetail = await context.Scheduler.GetJobDetail(chainRoot);
await context.Scheduler.AddJob(sjJobDetail!, true, false);
await context.Scheduler.TriggerJob(chainRoot, cancellationToken).ConfigureAwait(false);

View File

@@ -80,7 +80,7 @@ namespace Modbus.Net
IJobListener listener;
if (interval <= 0)
{
listener = new JobChainingJobLIstenerWithDataMapRepeated("Modbus.Net.DataQuery.Chain." + triggerKey, new string[2] { "Value", "SetValue" });
listener = new JobChainingJobLIstenerWithDataMapRepeated("Modbus.Net.DataQuery.Chain." + triggerKey, new string[2] { "Value", "SetValue" }, count);
}
else
{

View File

@@ -69,7 +69,7 @@ namespace MachineJob.Service
//5. 不设置固定时间连续触发Job
foreach (var machine in machines)
{
var scheduler = await MachineJobSchedulerCreator<IMachineMethodDatas, string, double>.CreateScheduler(machine.Id, 0, 0);
var scheduler = await MachineJobSchedulerCreator<IMachineMethodDatas, string, double>.CreateScheduler(machine.Id, -1, 0);
var job = scheduler.From(machine.Id + ".From", machine, MachineDataType.Name).Result.Query(machine.Id + ".ConsoleQuery", QueryConsole).Result.To(machine.Id + ".To", machine).Result.Deal(machine.Id + ".Deal", OnSuccess, OnFailure).Result;
await job.Run();
}