Skip to content

Commit

Permalink
fix : Fix duplicate registration of scheduler (#529)
Browse files Browse the repository at this point in the history
  • Loading branch information
wzh425 authored Jun 20, 2023
1 parent 7e1286f commit c8cde1d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ protected override async Task ExecutingAsync(ResolveMessageTaskJobArgs args)
return;

var receiverUsers = await _channelUserFinder.GetReceiverUsersAsync(messageTask.Channel, messageTask.Variables, messageTask.Receivers);
messageTask.ReceiverUsers.AddRange(receiverUsers);
messageTask.SetReceiverUsers(receiverUsers.ToList());

await _messageTaskHistoryRepository.RemoveAsync(x => x.MessageTaskId == args.MessageTaskId);

var sendTime = DateTimeOffset.Now;
if (messageTask.SendRules.IsCustom)
Expand Down Expand Up @@ -77,7 +79,7 @@ protected override async Task ExecutingAsync(ResolveMessageTaskJobArgs args)
var userId = _userContext.GetUserId<Guid>();
var operatorId = userId == default ? args.OperatorId : userId;

var jobId = await _messageTaskJobService.RegisterJobAsync(args.MessageTaskId, messageTask.SendRules.CronExpression, operatorId, messageTask.DisplayName);
var jobId = await _messageTaskJobService.RegisterJobAsync(messageTask.SchedulerJobId, args.MessageTaskId, messageTask.SendRules.CronExpression, operatorId, messageTask.DisplayName);
messageTask.SetJobId(jobId);

await _messageTaskRepository.UpdateAsync(messageTask);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ public virtual void SetDraft(bool isDraft)
}
}

public void SetReceiverUsers(List<MessageReceiverUser> receiverUsers)
{
ReceiverUsers = receiverUsers;
}

public virtual void UpdateVariables(ExtraPropertyDictionary variables)
{
Variables = variables;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Masa.Mc.Service.Admin.Domain.MessageTasks.Services;

public interface IMessageTaskJobService
{
Task<Guid> RegisterJobAsync(Guid messageTaskId, string cronExpression, Guid operatorId, string jobName);
Task<Guid> RegisterJobAsync(Guid jobId, Guid messageTaskId, string cronExpression, Guid operatorId, string jobName);

Task<bool> StartJobAsync(Guid jobId, Guid operatorId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public async Task<bool> EnableJobAsync(Guid jobId, Guid operatorId)
return await _schedulerClient.SchedulerJobService.DisableAsync(new SchedulerJobRequestBase { JobId = jobId, OperatorId = operatorId });
}

public async Task<Guid> RegisterJobAsync(Guid messageTaskId, string cronExpression, Guid operatorId, string jobName)
public async Task<Guid> RegisterJobAsync(Guid jobId, Guid messageTaskId, string cronExpression, Guid operatorId, string jobName)
{
var mcUrl = _masaStackConfig.GetMcServiceDomain();
var request = new UpsertSchedulerJobRequest
Expand All @@ -44,7 +44,14 @@ public async Task<Guid> RegisterJobAsync(Guid messageTaskId, string cronExpressi
NotifyUrl = $"{mcUrl}/api/message-task/HandleJobStatusNotify"
};

var jobId = await _schedulerClient.SchedulerJobService.AddAsync(request);
if (jobId == default)
{
jobId = await _schedulerClient.SchedulerJobService.AddAsync(request);
}
else
{
await _schedulerClient.SchedulerJobService.UpdateAsync(jobId, request);
}

return jobId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public async Task<bool> EnableJobAsync(Guid jobId, Guid operatorId)
return await _schedulerClient.SchedulerJobService.EnableAsync(new SchedulerJobRequestBase { JobId = jobId, OperatorId = operatorId });
}

public async Task<Guid> RegisterJobAsync(Guid messageTaskId, string cronExpression, Guid operatorId, string jobName)
public async Task<Guid> RegisterJobAsync(Guid jobId, Guid messageTaskId, string cronExpression, Guid operatorId, string jobName)
{
var mcUrl = _masaStackConfig.GetMcServiceDomain();
var parameters = new List<KeyValuePair<string, string>>() { new(nameof(messageTaskId), messageTaskId.ToString()) };
Expand All @@ -49,7 +49,14 @@ public async Task<Guid> RegisterJobAsync(Guid messageTaskId, string cronExpressi
NotifyUrl = $"{mcUrl}/api/message-task/HandleJobStatusNotify"
};

var jobId = await _schedulerClient.SchedulerJobService.AddAsync(request);
if (jobId == default)
{
jobId = await _schedulerClient.SchedulerJobService.AddAsync(request);
}
else
{
await _schedulerClient.SchedulerJobService.UpdateAsync(jobId, request);
}

return jobId;
}
Expand Down

0 comments on commit c8cde1d

Please sign in to comment.