@@ -20,6 +20,8 @@ public enum TaskDependencyAction<TaskDescription: TaskDescriptionProtocol> {
20
20
case cancelAndRescheduleDependency( TaskDescription )
21
21
}
22
22
23
+ private let taskSchedulerSubsystem = " org.swift.sourcekit-lsp.task-scheduler "
24
+
23
25
public protocol TaskDescriptionProtocol : Identifiable , Sendable , CustomLogStringConvertible {
24
26
/// Execute the task.
25
27
///
@@ -208,7 +210,14 @@ public actor QueuedTask<TaskDescription: TaskDescriptionProtocol> {
208
210
await withTaskGroup ( of: Void . self) { taskGroup in
209
211
taskGroup. addTask {
210
212
for await _ in updatePriorityStream {
211
- self . priority = Task . currentPriority
213
+ if Task . currentPriority != self . priority {
214
+ withLoggingSubsystemAndScope ( subsystem: taskSchedulerSubsystem, scope: nil ) {
215
+ logger. debug (
216
+ " Updating priority of \( self . description. forLogging) from \( self . priority. rawValue) to \( Task . currentPriority. rawValue) "
217
+ )
218
+ }
219
+ self . priority = Task . currentPriority
220
+ }
212
221
}
213
222
}
214
223
taskGroup. addTask {
@@ -296,6 +305,11 @@ public actor QueuedTask<TaskDescription: TaskDescriptionProtocol> {
296
305
/// a new task that depends on it. Otherwise a no-op.
297
306
nonisolated func elevatePriority( to targetPriority: TaskPriority ) {
298
307
if priority < targetPriority {
308
+ withLoggingSubsystemAndScope ( subsystem: taskSchedulerSubsystem, scope: nil ) {
309
+ logger. debug (
310
+ " Elevating priority of \( self . description. forLogging) from \( self . priority. rawValue) to \( targetPriority. rawValue) "
311
+ )
312
+ }
299
313
Task ( priority: targetPriority) {
300
314
await self . resultTask. value
301
315
}
@@ -428,13 +442,17 @@ public actor TaskScheduler<TaskDescription: TaskDescriptionProtocol> {
428
442
case . cancelAndRescheduleDependency( let taskDescription) :
429
443
guard let dependency = self . currentlyExecutingTasks. first ( where: { $0. description. id == taskDescription. id } )
430
444
else {
431
- logger. fault (
432
- " Cannot find task to wait for \( taskDescription. forLogging) in list of currently executing tasks "
433
- )
445
+ withLoggingSubsystemAndScope ( subsystem: taskSchedulerSubsystem, scope: nil ) {
446
+ logger. fault (
447
+ " Cannot find task to wait for \( taskDescription. forLogging) in list of currently executing tasks "
448
+ )
449
+ }
434
450
return nil
435
451
}
436
452
if !taskDescription. isIdempotent {
437
- logger. fault ( " Cannot reschedule task ' \( taskDescription. forLogging) ' since it is not idempotent " )
453
+ withLoggingSubsystemAndScope ( subsystem: taskSchedulerSubsystem, scope: nil ) {
454
+ logger. fault ( " Cannot reschedule task ' \( taskDescription. forLogging) ' since it is not idempotent " )
455
+ }
438
456
return dependency
439
457
}
440
458
if dependency. priority > task. priority {
@@ -445,9 +463,11 @@ public actor TaskScheduler<TaskDescription: TaskDescriptionProtocol> {
445
463
case . waitAndElevatePriorityOfDependency( let taskDescription) :
446
464
guard let dependency = self . currentlyExecutingTasks. first ( where: { $0. description. id == taskDescription. id } )
447
465
else {
448
- logger. fault (
449
- " Cannot find task to wait for ' \( taskDescription. forLogging) ' in list of currently executing tasks "
450
- )
466
+ withLoggingSubsystemAndScope ( subsystem: taskSchedulerSubsystem, scope: nil ) {
467
+ logger. fault (
468
+ " Cannot find task to wait for ' \( taskDescription. forLogging) ' in list of currently executing tasks "
469
+ )
470
+ }
451
471
return nil
452
472
}
453
473
return dependency
@@ -465,9 +485,11 @@ public actor TaskScheduler<TaskDescription: TaskDescriptionProtocol> {
465
485
switch taskDependency {
466
486
case . cancelAndRescheduleDependency( let taskDescription) :
467
487
guard let task = self . currentlyExecutingTasks. first ( where: { $0. description. id == taskDescription. id } ) else {
468
- logger. fault (
469
- " Cannot find task to reschedule \( taskDescription. forLogging) in list of currently executing tasks "
470
- )
488
+ withLoggingSubsystemAndScope ( subsystem: taskSchedulerSubsystem, scope: nil ) {
489
+ logger. fault (
490
+ " Cannot find task to reschedule \( taskDescription. forLogging) in list of currently executing tasks "
491
+ )
492
+ }
471
493
return nil
472
494
}
473
495
return task
@@ -478,6 +500,9 @@ public actor TaskScheduler<TaskDescription: TaskDescriptionProtocol> {
478
500
if !rescheduleTasks. isEmpty {
479
501
Task . detached ( priority: task. priority) {
480
502
for task in rescheduleTasks {
503
+ withLoggingSubsystemAndScope ( subsystem: taskSchedulerSubsystem, scope: nil ) {
504
+ logger. debug ( " Suspending \( task. description. forLogging) " )
505
+ }
481
506
await task. cancelToBeRescheduled ( )
482
507
}
483
508
}
0 commit comments