| | 1 | | using LGDXRobotCloud.API.Services.Common; |
| | 2 | | using LGDXRobotCloud.API.Services.Navigation; |
| | 3 | | using LGDXRobotCloud.Data.Contracts; |
| | 4 | | using LGDXRobotCloud.Data.DbContexts; |
| | 5 | | using LGDXRobotCloud.Data.Entities; |
| | 6 | | using LGDXRobotCloud.Protos; |
| | 7 | | using LGDXRobotCloud.Utilities.Enums; |
| | 8 | | using LGDXRobotCloud.Utilities.Helpers; |
| | 9 | | using MassTransit; |
| | 10 | | using Microsoft.EntityFrameworkCore; |
| | 11 | | using Microsoft.Extensions.Caching.Distributed; |
| | 12 | | using Microsoft.Extensions.Caching.Memory; |
| | 13 | |
|
| | 14 | | namespace LGDXRobotCloud.API.Services.Automation; |
| | 15 | |
|
| | 16 | | public interface IAutoTaskSchedulerService |
| | 17 | | { |
| | 18 | | void ResetIgnoreRobot(int realmId); |
| | 19 | | Task<RobotClientsAutoTask?> GetAutoTaskAsync(Guid robotId); |
| | 20 | | Task<RobotClientsAutoTask?> AutoTaskAbortAsync(Guid robotId, int taskId, string token, AutoTaskAbortReason autoTaskAbo |
| | 21 | | Task<bool> AutoTaskAbortApiAsync(int taskId); |
| | 22 | | Task<RobotClientsAutoTask?> AutoTaskNextAsync(Guid robotId, int taskId, string token); |
| | 23 | | Task<AutoTask?> AutoTaskNextApiAsync(Guid robotId, int taskId, string token); |
| | 24 | | Task<RobotClientsAutoTask?> AutoTaskNextConstructAsync(AutoTask autoTask); |
| | 25 | | } |
| | 26 | |
|
| 20 | 27 | | public class AutoTaskSchedulerService( |
| 20 | 28 | | IBus bus, |
| 20 | 29 | | IEmailService emailService, |
| 20 | 30 | | IMemoryCache memoryCache, |
| 20 | 31 | | IOnlineRobotsService onlineRobotsService, |
| 20 | 32 | | IRobotService robotService, |
| 20 | 33 | | ITriggerService triggerService, |
| 20 | 34 | | LgdxContext context |
| 20 | 35 | | ) : IAutoTaskSchedulerService |
| | 36 | | { |
| 20 | 37 | | private readonly IBus _bus = bus ?? throw new ArgumentNullException(nameof(bus)); |
| 20 | 38 | | private readonly IEmailService _emailService = emailService ?? throw new ArgumentNullException(nameof(emailService)); |
| 20 | 39 | | private readonly IMemoryCache _memoryCache = memoryCache ?? throw new ArgumentNullException(nameof(memoryCache)); |
| 20 | 40 | | private readonly IOnlineRobotsService _onlineRobotsService = onlineRobotsService ?? throw new ArgumentNullException(na |
| 20 | 41 | | private readonly IRobotService _robotService = robotService ?? throw new ArgumentNullException(nameof(robotService)); |
| 20 | 42 | | private readonly ITriggerService _triggerService = triggerService ?? throw new ArgumentNullException(nameof(triggerSer |
| 20 | 43 | | private readonly LgdxContext _context = context ?? throw new ArgumentNullException(nameof(context)); |
| 11 | 44 | | private static string GetIgnoreRobotsKey(int realmId) => $"AutoTaskSchedulerService_IgnoreRobot_{realmId}"; |
| | 45 | |
|
| | 46 | | private async Task AddAutoTaskJourney(AutoTask autoTask) |
| 7 | 47 | | { |
| 7 | 48 | | var autoTaskJourney = new AutoTaskJourney |
| 7 | 49 | | { |
| 7 | 50 | | AutoTaskId = autoTask.Id, |
| 7 | 51 | | CurrentProgressId = autoTask.CurrentProgressId |
| 7 | 52 | | }; |
| 7 | 53 | | await _context.AutoTasksJourney.AddAsync(autoTaskJourney); |
| 7 | 54 | | await _context.SaveChangesAsync(); |
| 7 | 55 | | } |
| | 56 | |
|
| | 57 | | private static RobotClientsDof GenerateWaypoint(AutoTaskDetail taskDetail) |
| 8 | 58 | | { |
| 8 | 59 | | if (taskDetail.Waypoint != null) |
| 4 | 60 | | { |
| 4 | 61 | | var waypoint = new RobotClientsDof |
| 4 | 62 | | { X = taskDetail.Waypoint.X, Y = taskDetail.Waypoint.Y, Rotation = taskDetail.Waypoint.Rotation }; |
| 4 | 63 | | if (taskDetail.CustomX != null) |
| 1 | 64 | | waypoint.X = (double)taskDetail.CustomX; |
| 4 | 65 | | if (taskDetail.CustomY != null) |
| 1 | 66 | | waypoint.X = (double)taskDetail.CustomY; |
| 4 | 67 | | if (taskDetail.CustomRotation != null) |
| 1 | 68 | | waypoint.X = (double)taskDetail.CustomRotation; |
| 4 | 69 | | return waypoint; |
| | 70 | | } |
| | 71 | | else |
| 4 | 72 | | { |
| 4 | 73 | | return new RobotClientsDof |
| 4 | 74 | | { |
| 4 | 75 | | X = taskDetail.CustomX != null ? (double)taskDetail.CustomX : 0, |
| 4 | 76 | | Y = taskDetail.CustomY != null ? (double)taskDetail.CustomY : 0, |
| 4 | 77 | | Rotation = taskDetail.CustomRotation != null ? (double)taskDetail.CustomRotation : 0 |
| 4 | 78 | | }; |
| | 79 | | } |
| 8 | 80 | | } |
| | 81 | |
|
| | 82 | | private async Task<RobotClientsAutoTask?> GenerateTaskDetail(AutoTask? task, bool continueAutoTask = false) |
| 13 | 83 | | { |
| 13 | 84 | | if (task == null) |
| 3 | 85 | | { |
| 3 | 86 | | return null; |
| | 87 | | } |
| | 88 | |
|
| 10 | 89 | | var progress = await _context.Progresses.AsNoTracking() |
| 10 | 90 | | .Where(p => p.Id == task.CurrentProgressId) |
| 10 | 91 | | .Select(p => new { p.Name }) |
| 10 | 92 | | .FirstOrDefaultAsync(); |
| 10 | 93 | | if (!continueAutoTask) |
| 6 | 94 | | { |
| | 95 | | // Notify the updated task |
| 6 | 96 | | var flowName = await _context.Flows.AsNoTracking() |
| 6 | 97 | | .Where(f => f.Id == task.FlowId) |
| 6 | 98 | | .Select(f => f.Name) |
| 6 | 99 | | .FirstOrDefaultAsync(); |
| 6 | 100 | | string? robotName = null; |
| 6 | 101 | | if (task.AssignedRobotId != null) |
| 6 | 102 | | { |
| 6 | 103 | | robotName = await _context.Robots.AsNoTracking() |
| 6 | 104 | | .Where(r => r.Id == task.AssignedRobotId) |
| 6 | 105 | | .Select(r => r.Name) |
| 6 | 106 | | .FirstOrDefaultAsync(); |
| 6 | 107 | | } |
| 6 | 108 | | await _bus.Publish(new AutoTaskUpdateContract{ |
| 6 | 109 | | Id = task.Id, |
| 6 | 110 | | Name = task.Name, |
| 6 | 111 | | Priority = task.Priority, |
| 6 | 112 | | FlowId = task.FlowId ?? 0, |
| 6 | 113 | | FlowName = flowName ?? "Deleted Flow", |
| 6 | 114 | | RealmId = task.RealmId, |
| 6 | 115 | | AssignedRobotId = task.AssignedRobotId, |
| 6 | 116 | | AssignedRobotName = robotName, |
| 6 | 117 | | CurrentProgressId = task.CurrentProgressId, |
| 6 | 118 | | CurrentProgressName = progress!.Name, |
| 6 | 119 | | }); |
| 6 | 120 | | } |
| | 121 | |
|
| 10 | 122 | | if (task.CurrentProgressId == (int)ProgressState.Completed || task.CurrentProgressId == (int)ProgressState.Aborted) |
| 2 | 123 | | { |
| | 124 | | // Return immediately if the task is completed / aborted |
| 2 | 125 | | return new RobotClientsAutoTask { |
| 2 | 126 | | TaskId = task.Id, |
| 2 | 127 | | TaskName = task.Name ?? string.Empty, |
| 2 | 128 | | TaskProgressId = task.CurrentProgressId, |
| 2 | 129 | | TaskProgressName = progress!.Name ?? string.Empty, |
| 2 | 130 | | Waypoints = {}, |
| 2 | 131 | | NextToken = string.Empty, |
| 2 | 132 | | }; |
| | 133 | | } |
| | 134 | |
|
| 8 | 135 | | var flowDetail = await _context.FlowDetails.AsNoTracking() |
| 8 | 136 | | .Where(fd => fd.FlowId == task.FlowId && fd.Order == (int)task.CurrentProgressOrder!) |
| 8 | 137 | | .FirstOrDefaultAsync(); |
| 8 | 138 | | if (!continueAutoTask && flowDetail!.TriggerId != null) |
| 1 | 139 | | { |
| | 140 | | // Fire the trigger |
| 1 | 141 | | await _triggerService.InitialiseTriggerAsync(task, flowDetail); |
| 1 | 142 | | } |
| | 143 | |
|
| 8 | 144 | | List<RobotClientsDof> waypoints = []; |
| 8 | 145 | | if (task.CurrentProgressId == (int)ProgressState.PreMoving) |
| 1 | 146 | | { |
| 1 | 147 | | var firstTaskDetail = await _context.AutoTasksDetail.AsNoTracking() |
| 1 | 148 | | .Where(t => t.AutoTaskId == task.Id) |
| 1 | 149 | | .Include(t => t.Waypoint) |
| 1 | 150 | | .OrderBy(t => t.Order) |
| 1 | 151 | | .FirstOrDefaultAsync(); |
| 1 | 152 | | if (firstTaskDetail != null) |
| 1 | 153 | | waypoints.Add(GenerateWaypoint(firstTaskDetail)); |
| 1 | 154 | | } |
| 7 | 155 | | else if (task.CurrentProgressId == (int)ProgressState.Moving) |
| 6 | 156 | | { |
| 6 | 157 | | var taskDetails = await _context.AutoTasksDetail.AsNoTracking() |
| 6 | 158 | | .Where(t => t.AutoTaskId == task.Id) |
| 6 | 159 | | .Include(t => t.Waypoint) |
| 6 | 160 | | .OrderBy(t => t.Order) |
| 6 | 161 | | .ToListAsync(); |
| 32 | 162 | | foreach (var t in taskDetails) |
| 7 | 163 | | { |
| 7 | 164 | | waypoints.Add(GenerateWaypoint(t)); |
| 7 | 165 | | } |
| 6 | 166 | | } |
| | 167 | |
|
| 8 | 168 | | string nextToken = task.NextToken ?? string.Empty; |
| 8 | 169 | | if (flowDetail?.AutoTaskNextControllerId != (int) AutoTaskNextController.Robot) |
| 1 | 170 | | { |
| | 171 | | // API has the control |
| 1 | 172 | | nextToken = string.Empty; |
| 1 | 173 | | } |
| | 174 | |
|
| 8 | 175 | | return new RobotClientsAutoTask { |
| 8 | 176 | | TaskId = task.Id, |
| 8 | 177 | | TaskName = task.Name ?? string.Empty, |
| 8 | 178 | | TaskProgressId = task.CurrentProgressId, |
| 8 | 179 | | TaskProgressName = progress!.Name ?? string.Empty, |
| 8 | 180 | | Waypoints = { waypoints }, |
| 8 | 181 | | NextToken = nextToken, |
| 8 | 182 | | }; |
| 13 | 183 | | } |
| | 184 | |
|
| | 185 | | public void ResetIgnoreRobot(int realmId) |
| 1 | 186 | | { |
| 1 | 187 | | _memoryCache.Remove(GetIgnoreRobotsKey(realmId)); |
| 1 | 188 | | } |
| | 189 | |
|
| | 190 | | private async Task<AutoTask?> GetRunningAutoTaskSqlAsync(Guid robotId) |
| 8 | 191 | | { |
| 8 | 192 | | return await _context.AutoTasks.AsNoTracking() |
| 8 | 193 | | .Include(t => t.AutoTaskDetails) |
| 8 | 194 | | .Where(t => t.AssignedRobotId == robotId) |
| 8 | 195 | | .Where(t => !LgdxHelper.AutoTaskStaticStates.Contains(t.CurrentProgressId)) |
| 8 | 196 | | .OrderByDescending(t => t.Priority) // In case the robot has multiple running task by mistake |
| 8 | 197 | | .ThenByDescending(t => t.AssignedRobotId) |
| 8 | 198 | | .ThenBy(t => t.Id) |
| 8 | 199 | | .FirstOrDefaultAsync(); |
| 8 | 200 | | } |
| | 201 | |
|
| | 202 | | private async Task<AutoTask?> AssignAutoTaskSqlAsync(Guid robotId) |
| 3 | 203 | | { |
| 3 | 204 | | AutoTask? task = null; |
| 3 | 205 | | using var transaction = await _context.Database.BeginTransactionAsync(); |
| | 206 | | try |
| 3 | 207 | | { |
| | 208 | | // Get waiting task |
| 3 | 209 | | task = await _context.AutoTasks.FromSql( |
| 3 | 210 | | $@"SELECT * FROM ""Automation.AutoTasks"" AS T |
| 3 | 211 | | WHERE T.""CurrentProgressId"" = {(int)ProgressState.Waiting} AND (T.""AssignedRobotId"" = {robotId} OR T.""A |
| 3 | 212 | | ORDER BY T.""Priority"" DESC, T.""AssignedRobotId"" DESC, T.""Id"" |
| 3 | 213 | | LIMIT 1 FOR UPDATE SKIP LOCKED" |
| 3 | 214 | | ).FirstOrDefaultAsync(); |
| | 215 | |
|
| | 216 | | // Get flow detail |
| 3 | 217 | | var flowDetail = await _context.FlowDetails |
| 3 | 218 | | .Where(f => f.FlowId == task!.FlowId) |
| 3 | 219 | | .Select(f => new { |
| 3 | 220 | | f.ProgressId, |
| 3 | 221 | | f.Order |
| 3 | 222 | | }) |
| 3 | 223 | | .OrderBy(f => f.Order) |
| 3 | 224 | | .FirstOrDefaultAsync(); |
| | 225 | |
|
| | 226 | | // Update task |
| 2 | 227 | | task!.AssignedRobotId = robotId; |
| 2 | 228 | | task.CurrentProgressId = flowDetail!.ProgressId; |
| 2 | 229 | | task.CurrentProgressOrder = flowDetail.Order; |
| 2 | 230 | | task.NextToken = LgdxHelper.GenerateMd5Hash($"{robotId} {task.Id} {task.CurrentProgressId} {DateTime.UtcNow}"); |
| 2 | 231 | | await _context.SaveChangesAsync(); |
| 2 | 232 | | await transaction.CommitAsync(); |
| 2 | 233 | | return task; |
| | 234 | | } |
| 1 | 235 | | catch (Exception) |
| 1 | 236 | | { |
| 1 | 237 | | await transaction.RollbackAsync(); |
| 1 | 238 | | } |
| 1 | 239 | | return null; |
| 3 | 240 | | } |
| | 241 | |
|
| | 242 | | public async Task<RobotClientsAutoTask?> GetAutoTaskAsync(Guid robotId) |
| 9 | 243 | | { |
| 9 | 244 | | var realmId = await _robotService.GetRobotRealmIdAsync(robotId) ?? 0; |
| 9 | 245 | | _memoryCache.TryGetValue(GetIgnoreRobotsKey(realmId), out HashSet<Guid>? ignoreRobotIds); |
| 9 | 246 | | if (ignoreRobotIds != null && (ignoreRobotIds?.Contains(robotId) ?? false)) |
| 1 | 247 | | { |
| 1 | 248 | | return null; |
| | 249 | | } |
| | 250 | |
|
| 8 | 251 | | var currentTask = await GetRunningAutoTaskSqlAsync(robotId); |
| 8 | 252 | | bool continueAutoTask = currentTask != null; |
| 8 | 253 | | if (currentTask == null) |
| 4 | 254 | | { |
| 4 | 255 | | if (!_onlineRobotsService.GetPauseAutoTaskAssignment(robotId)) |
| 3 | 256 | | { |
| 3 | 257 | | currentTask = await AssignAutoTaskSqlAsync(robotId); |
| 3 | 258 | | if (currentTask != null) |
| 2 | 259 | | { |
| 2 | 260 | | await AddAutoTaskJourney(currentTask); |
| 2 | 261 | | } |
| 3 | 262 | | } |
| | 263 | | else |
| 1 | 264 | | { |
| | 265 | | // If pause auto task assignment is true, new task will not be assigned. |
| 1 | 266 | | return null; |
| | 267 | | } |
| 3 | 268 | | } |
| | 269 | |
|
| 7 | 270 | | if (currentTask == null) |
| 1 | 271 | | { |
| | 272 | | // No task for this robot, pause database access. |
| 1 | 273 | | ignoreRobotIds ??= []; |
| 1 | 274 | | ignoreRobotIds.Add(robotId); |
| 1 | 275 | | _memoryCache.Set(GetIgnoreRobotsKey(realmId), ignoreRobotIds, TimeSpan.FromMinutes(5)); |
| 1 | 276 | | } |
| 7 | 277 | | return await GenerateTaskDetail(currentTask, continueAutoTask); |
| 9 | 278 | | } |
| | 279 | |
|
| | 280 | | private async Task<AutoTask?> AutoTaskAbortSqlAsync(int taskId, Guid? robotId = null, string? token = null) |
| 4 | 281 | | { |
| 4 | 282 | | AutoTask? task = null; |
| 4 | 283 | | using var transaction = await _context.Database.BeginTransactionAsync(); |
| | 284 | | try |
| 4 | 285 | | { |
| | 286 | | // Get task |
| 4 | 287 | | if (robotId == null && string.IsNullOrWhiteSpace(token)) |
| 2 | 288 | | { |
| | 289 | | // From API |
| 2 | 290 | | task = await _context.AutoTasks.FromSql( |
| 2 | 291 | | $@"SELECT * FROM ""Automation.AutoTasks"" AS T |
| 2 | 292 | | WHERE T.""Id"" = {taskId} |
| 2 | 293 | | LIMIT 1 FOR UPDATE NOWAIT" |
| 2 | 294 | | ).FirstOrDefaultAsync(); |
| 2 | 295 | | } |
| | 296 | | else |
| 2 | 297 | | { |
| 2 | 298 | | task = await _context.AutoTasks.FromSql( |
| 2 | 299 | | $@"SELECT * FROM ""Automation.AutoTasks"" AS T |
| 2 | 300 | | WHERE T.""Id"" = {taskId} AND T.""AssignedRobotId"" = {robotId} AND T.""NextToken"" = {token} |
| 2 | 301 | | LIMIT 1 FOR UPDATE NOWAIT" |
| 2 | 302 | | ).FirstOrDefaultAsync(); |
| 2 | 303 | | } |
| | 304 | |
|
| | 305 | | // Update task |
| 4 | 306 | | task!.CurrentProgressId = (int)ProgressState.Aborted; |
| 2 | 307 | | task.CurrentProgressOrder = null; |
| 2 | 308 | | task.NextToken = null; |
| 2 | 309 | | await _context.SaveChangesAsync(); |
| 2 | 310 | | await transaction.CommitAsync(); |
| 2 | 311 | | } |
| 2 | 312 | | catch (Exception) |
| 2 | 313 | | { |
| 2 | 314 | | await transaction.RollbackAsync(); |
| 2 | 315 | | } |
| 4 | 316 | | return task; |
| 4 | 317 | | } |
| | 318 | |
|
| | 319 | | private async Task DeleteTriggerRetries(int taskId) |
| 2 | 320 | | { |
| 2 | 321 | | var count = await _context.TriggerRetries.Where(tr => tr.AutoTaskId == taskId).CountAsync(); |
| 2 | 322 | | if (count > 0) |
| 0 | 323 | | { |
| 0 | 324 | | await _context.TriggerRetries.Where(tr => tr.AutoTaskId == taskId).ExecuteDeleteAsync(); |
| 0 | 325 | | } |
| 2 | 326 | | } |
| | 327 | |
|
| | 328 | | public async Task<RobotClientsAutoTask?> AutoTaskAbortAsync(Guid robotId, int taskId, string token, AutoTaskAbortReaso |
| 2 | 329 | | { |
| 2 | 330 | | var task = await AutoTaskAbortSqlAsync(taskId, robotId, token); |
| 2 | 331 | | if (task != null) |
| 1 | 332 | | { |
| 1 | 333 | | await DeleteTriggerRetries(taskId); |
| 1 | 334 | | await _emailService.SendAutoTaskAbortEmailAsync(robotId, taskId, autoTaskAbortReason); |
| 1 | 335 | | await AddAutoTaskJourney(task); |
| 1 | 336 | | } |
| 2 | 337 | | return await GenerateTaskDetail(task); |
| 2 | 338 | | } |
| | 339 | |
|
| | 340 | | public async Task<bool> AutoTaskAbortApiAsync(int taskId) |
| 2 | 341 | | { |
| 2 | 342 | | var task = await AutoTaskAbortSqlAsync(taskId); |
| 2 | 343 | | if (task == null) |
| 1 | 344 | | return false; |
| | 345 | |
|
| 1 | 346 | | await DeleteTriggerRetries(taskId); |
| 1 | 347 | | await _emailService.SendAutoTaskAbortEmailAsync((Guid)task!.AssignedRobotId!, taskId, AutoTaskAbortReason.UserApi); |
| 1 | 348 | | await AddAutoTaskJourney(task); |
| 1 | 349 | | return true; |
| 2 | 350 | | } |
| | 351 | |
|
| | 352 | | private async Task<AutoTask?> AutoTaskNextSqlAsync(Guid robotId, int taskId, string token) |
| 5 | 353 | | { |
| 5 | 354 | | AutoTask? task = null; |
| 5 | 355 | | using var transaction = await _context.Database.BeginTransactionAsync(); |
| | 356 | | try |
| 5 | 357 | | { |
| | 358 | | // Get waiting task |
| 5 | 359 | | task = await _context.AutoTasks.FromSql( |
| 5 | 360 | | $@"SELECT * FROM ""Automation.AutoTasks"" AS T |
| 5 | 361 | | WHERE T.""Id"" = {taskId} AND T.""AssignedRobotId"" = {robotId} AND T.""NextToken"" = {token} |
| 5 | 362 | | LIMIT 1 FOR UPDATE NOWAIT" |
| 5 | 363 | | ).FirstOrDefaultAsync(); |
| | 364 | |
|
| | 365 | | // Get flow detail |
| 5 | 366 | | var flowDetail = await _context.FlowDetails.AsNoTracking() |
| 5 | 367 | | .Where(f => f.FlowId == task!.FlowId) |
| 5 | 368 | | .Where(f => f.Order > task!.CurrentProgressOrder) |
| 5 | 369 | | .Select(f => new { |
| 5 | 370 | | f.ProgressId, |
| 5 | 371 | | f.Order |
| 5 | 372 | | }) |
| 5 | 373 | | .OrderBy(f => f.Order) |
| 5 | 374 | | .FirstOrDefaultAsync(); |
| | 375 | |
|
| | 376 | | // Update task |
| 3 | 377 | | if (flowDetail != null) |
| 2 | 378 | | { |
| 2 | 379 | | task!.CurrentProgressId = flowDetail!.ProgressId; |
| 2 | 380 | | task.CurrentProgressOrder = flowDetail.Order; |
| 2 | 381 | | task.NextToken = LgdxHelper.GenerateMd5Hash($"{robotId} {task.Id} {task.CurrentProgressId} {DateTime.UtcNow}"); |
| 2 | 382 | | } |
| | 383 | | else |
| 1 | 384 | | { |
| 1 | 385 | | task!.CurrentProgressId = (int)ProgressState.Completed; |
| 1 | 386 | | task.CurrentProgressOrder = null; |
| 1 | 387 | | task.NextToken = null; |
| 1 | 388 | | } |
| | 389 | |
|
| 3 | 390 | | await _context.SaveChangesAsync(); |
| 3 | 391 | | await transaction.CommitAsync(); |
| 3 | 392 | | } |
| 2 | 393 | | catch (Exception) |
| 2 | 394 | | { |
| 2 | 395 | | await transaction.RollbackAsync(); |
| 2 | 396 | | } |
| 5 | 397 | | return task; |
| 5 | 398 | | } |
| | 399 | |
|
| | 400 | | public async Task<RobotClientsAutoTask?> AutoTaskNextAsync(Guid robotId, int taskId, string token) |
| 3 | 401 | | { |
| 3 | 402 | | var task = await AutoTaskNextSqlAsync(robotId, taskId, token); |
| 3 | 403 | | if (task != null) |
| 2 | 404 | | { |
| 2 | 405 | | await AddAutoTaskJourney(task); |
| 2 | 406 | | } |
| 3 | 407 | | return await GenerateTaskDetail(task); |
| 3 | 408 | | } |
| | 409 | |
|
| | 410 | | public async Task<AutoTask?> AutoTaskNextApiAsync(Guid robotId, int taskId, string token) |
| 2 | 411 | | { |
| 2 | 412 | | var task = await AutoTaskNextSqlAsync(robotId, taskId, token); |
| 2 | 413 | | if (task != null) |
| 1 | 414 | | { |
| 1 | 415 | | await AddAutoTaskJourney(task); |
| 1 | 416 | | } |
| 2 | 417 | | return task; |
| 2 | 418 | | } |
| | 419 | |
|
| | 420 | | public async Task<RobotClientsAutoTask?> AutoTaskNextConstructAsync(AutoTask autoTask) |
| 1 | 421 | | { |
| 1 | 422 | | return await GenerateTaskDetail(autoTask); |
| 1 | 423 | | } |
| | 424 | | } |