@@ -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
///
@@ -232,9 +234,11 @@ fileprivate actor QueuedTask<TaskDescription: TaskDescriptionProtocol> {
232
234
/// a new task that depends on it. Otherwise a no-op.
233
235
nonisolated func elevatePriority( to targetPriority: TaskPriority ) {
234
236
if priority < targetPriority {
235
- logger. debug (
236
- " Elevating priority of \( self . description. forLogging) from \( self . priority. rawValue) to \( targetPriority. rawValue) "
237
- )
237
+ withLoggingSubsystemAndScope ( subsystem: taskSchedulerSubsystem, scope: nil ) {
238
+ logger. debug (
239
+ " Elevating priority of \( self . description. forLogging) from \( self . priority. rawValue) to \( targetPriority. rawValue) "
240
+ )
241
+ }
238
242
Task ( priority: targetPriority) {
239
243
await self . resultTask. value
240
244
}
@@ -306,7 +310,9 @@ public actor TaskScheduler<TaskDescription: TaskDescriptionProtocol> {
306
310
priority: TaskPriority ? = nil ,
307
311
_ taskDescription: TaskDescription
308
312
) async -> Task < Void , Never > {
309
- logger. debug ( " Scheduling \( taskDescription. forLogging) " )
313
+ withLoggingSubsystemAndScope ( subsystem: taskSchedulerSubsystem, scope: nil ) {
314
+ logger. debug ( " Scheduling \( taskDescription. forLogging) " )
315
+ }
310
316
let queuedTask = await QueuedTask ( priority: priority, description: taskDescription)
311
317
pendingTasks. append ( queuedTask)
312
318
Task . detached ( priority: priority ?? Task . currentPriority) {
@@ -361,13 +367,17 @@ public actor TaskScheduler<TaskDescription: TaskDescriptionProtocol> {
361
367
case . cancelAndRescheduleDependency( let taskDescription) :
362
368
guard let dependency = self . currentlyExecutingTasks. first ( where: { $0. description. id == taskDescription. id } )
363
369
else {
364
- logger. fault (
365
- " Cannot find task to wait for \( taskDescription. forLogging) in list of currently executing tasks "
366
- )
370
+ withLoggingSubsystemAndScope ( subsystem: taskSchedulerSubsystem, scope: nil ) {
371
+ logger. fault (
372
+ " Cannot find task to wait for \( taskDescription. forLogging) in list of currently executing tasks "
373
+ )
374
+ }
367
375
return nil
368
376
}
369
377
if !taskDescription. isIdempotent {
370
- logger. fault ( " Cannot reschedule task ' \( taskDescription. forLogging) ' since it is not idempotent " )
378
+ withLoggingSubsystemAndScope ( subsystem: taskSchedulerSubsystem, scope: nil ) {
379
+ logger. fault ( " Cannot reschedule task ' \( taskDescription. forLogging) ' since it is not idempotent " )
380
+ }
371
381
return dependency
372
382
}
373
383
if dependency. priority > task. priority {
@@ -378,9 +388,11 @@ public actor TaskScheduler<TaskDescription: TaskDescriptionProtocol> {
378
388
case . waitAndElevatePriorityOfDependency( let taskDescription) :
379
389
guard let dependency = self . currentlyExecutingTasks. first ( where: { $0. description. id == taskDescription. id } )
380
390
else {
381
- logger. fault (
382
- " Cannot find task to wait for ' \( taskDescription. forLogging) ' in list of currently executing tasks "
383
- )
391
+ withLoggingSubsystemAndScope ( subsystem: taskSchedulerSubsystem, scope: nil ) {
392
+ logger. fault (
393
+ " Cannot find task to wait for ' \( taskDescription. forLogging) ' in list of currently executing tasks "
394
+ )
395
+ }
384
396
return nil
385
397
}
386
398
return dependency
@@ -398,9 +410,11 @@ public actor TaskScheduler<TaskDescription: TaskDescriptionProtocol> {
398
410
switch taskDependency {
399
411
case . cancelAndRescheduleDependency( let taskDescription) :
400
412
guard let task = self . currentlyExecutingTasks. first ( where: { $0. description. id == taskDescription. id } ) else {
401
- logger. fault (
402
- " Cannot find task to reschedule \( taskDescription. forLogging) in list of currently executing tasks "
403
- )
413
+ withLoggingSubsystemAndScope ( subsystem: taskSchedulerSubsystem, scope: nil ) {
414
+ logger. fault (
415
+ " Cannot find task to reschedule \( taskDescription. forLogging) in list of currently executing tasks "
416
+ )
417
+ }
404
418
return nil
405
419
}
406
420
return task
@@ -411,7 +425,9 @@ public actor TaskScheduler<TaskDescription: TaskDescriptionProtocol> {
411
425
if !rescheduleTasks. isEmpty {
412
426
Task . detached ( priority: task. priority) {
413
427
for task in rescheduleTasks {
414
- logger. debug ( " Suspending \( task. description. forLogging) " )
428
+ withLoggingSubsystemAndScope ( subsystem: taskSchedulerSubsystem, scope: nil ) {
429
+ logger. debug ( " Suspending \( task. description. forLogging) " )
430
+ }
415
431
await task. cancelToBeRescheduled ( )
416
432
}
417
433
}
@@ -422,19 +438,25 @@ public actor TaskScheduler<TaskDescription: TaskDescriptionProtocol> {
422
438
return
423
439
}
424
440
425
- logger. debug ( " Executing \( task. description. forLogging) with priority \( task. priority. rawValue) " )
441
+ withLoggingSubsystemAndScope ( subsystem: taskSchedulerSubsystem, scope: nil ) {
442
+ logger. debug ( " Executing \( task. description. forLogging) with priority \( task. priority. rawValue) " )
443
+ }
426
444
currentlyExecutingTasks. append ( task)
427
445
pendingTasks. removeAll ( where: { $0 === task } )
428
446
Task . detached ( priority: task. priority) {
429
- logger. debug (
430
- " Execution of \( task. description. forLogging) started with priority \( Task . currentPriority. rawValue) "
431
- )
447
+ withLoggingSubsystemAndScope ( subsystem: taskSchedulerSubsystem, scope: nil ) {
448
+ logger. debug (
449
+ " Execution of \( task. description. forLogging) started with priority \( Task . currentPriority. rawValue) "
450
+ )
451
+ }
432
452
// Await the task's return in a task so that this poker can continue checking if there are more execution
433
453
// slots that can be filled with queued tasks.
434
454
let finishStatus = await task. execute ( )
435
- logger. debug (
436
- " Execution of \( task. description. forLogging) finished with priority \( Task . currentPriority. rawValue) "
437
- )
455
+ withLoggingSubsystemAndScope ( subsystem: taskSchedulerSubsystem, scope: nil ) {
456
+ logger. debug (
457
+ " Execution of \( task. description. forLogging) finished with priority \( Task . currentPriority. rawValue) "
458
+ )
459
+ }
438
460
await self . finalizeTaskExecution ( task: task, finishStatus: finishStatus)
439
461
}
440
462
}
0 commit comments