Skip to content

Remove status logging from TaskScheduler #1319

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 10 additions & 44 deletions Sources/SKCore/TaskScheduler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ public enum TaskDependencyAction<TaskDescription: TaskDescriptionProtocol> {
case cancelAndRescheduleDependency(TaskDescription)
}

private let taskSchedulerSubsystem = "org.swift.sourcekit-lsp.task-scheduler"

public protocol TaskDescriptionProtocol: Identifiable, Sendable, CustomLogStringConvertible {
/// Execute the task.
///
Expand Down Expand Up @@ -259,11 +257,6 @@ fileprivate actor QueuedTask<TaskDescription: TaskDescriptionProtocol> {
/// a new task that depends on it. Otherwise a no-op.
nonisolated func elevatePriority(to targetPriority: TaskPriority) {
if priority < targetPriority {
withLoggingSubsystemAndScope(subsystem: taskSchedulerSubsystem, scope: nil) {
logger.debug(
"Elevating priority of \(self.description.forLogging) from \(self.priority.rawValue) to \(targetPriority.rawValue)"
)
}
Task(priority: targetPriority) {
await self.resultTask.value
}
Expand Down Expand Up @@ -336,9 +329,6 @@ public actor TaskScheduler<TaskDescription: TaskDescriptionProtocol> {
_ taskDescription: TaskDescription,
@_inheritActorContext executionStateChangedCallback: (@Sendable (TaskExecutionState) async -> Void)? = nil
) async -> Task<Void, Never> {
withLoggingSubsystemAndScope(subsystem: taskSchedulerSubsystem, scope: nil) {
logger.debug("Scheduling \(taskDescription.forLogging)")
}
let queuedTask = await QueuedTask(
priority: priority,
description: taskDescription,
Expand Down Expand Up @@ -397,17 +387,13 @@ public actor TaskScheduler<TaskDescription: TaskDescriptionProtocol> {
case .cancelAndRescheduleDependency(let taskDescription):
guard let dependency = self.currentlyExecutingTasks.first(where: { $0.description.id == taskDescription.id })
else {
withLoggingSubsystemAndScope(subsystem: taskSchedulerSubsystem, scope: nil) {
logger.fault(
"Cannot find task to wait for \(taskDescription.forLogging) in list of currently executing tasks"
)
}
logger.fault(
"Cannot find task to wait for \(taskDescription.forLogging) in list of currently executing tasks"
)
return nil
}
if !taskDescription.isIdempotent {
withLoggingSubsystemAndScope(subsystem: taskSchedulerSubsystem, scope: nil) {
logger.fault("Cannot reschedule task '\(taskDescription.forLogging)' since it is not idempotent")
}
logger.fault("Cannot reschedule task '\(taskDescription.forLogging)' since it is not idempotent")
return dependency
}
if dependency.priority > task.priority {
Expand All @@ -418,11 +404,9 @@ public actor TaskScheduler<TaskDescription: TaskDescriptionProtocol> {
case .waitAndElevatePriorityOfDependency(let taskDescription):
guard let dependency = self.currentlyExecutingTasks.first(where: { $0.description.id == taskDescription.id })
else {
withLoggingSubsystemAndScope(subsystem: taskSchedulerSubsystem, scope: nil) {
logger.fault(
"Cannot find task to wait for '\(taskDescription.forLogging)' in list of currently executing tasks"
)
}
logger.fault(
"Cannot find task to wait for '\(taskDescription.forLogging)' in list of currently executing tasks"
)
return nil
}
return dependency
Expand All @@ -440,11 +424,9 @@ public actor TaskScheduler<TaskDescription: TaskDescriptionProtocol> {
switch taskDependency {
case .cancelAndRescheduleDependency(let taskDescription):
guard let task = self.currentlyExecutingTasks.first(where: { $0.description.id == taskDescription.id }) else {
withLoggingSubsystemAndScope(subsystem: taskSchedulerSubsystem, scope: nil) {
logger.fault(
"Cannot find task to reschedule \(taskDescription.forLogging) in list of currently executing tasks"
)
}
logger.fault(
"Cannot find task to reschedule \(taskDescription.forLogging) in list of currently executing tasks"
)
return nil
}
return task
Expand All @@ -455,9 +437,6 @@ public actor TaskScheduler<TaskDescription: TaskDescriptionProtocol> {
if !rescheduleTasks.isEmpty {
Task.detached(priority: task.priority) {
for task in rescheduleTasks {
withLoggingSubsystemAndScope(subsystem: taskSchedulerSubsystem, scope: nil) {
logger.debug("Suspending \(task.description.forLogging)")
}
await task.cancelToBeRescheduled()
}
}
Expand All @@ -468,25 +447,12 @@ public actor TaskScheduler<TaskDescription: TaskDescriptionProtocol> {
return
}

withLoggingSubsystemAndScope(subsystem: taskSchedulerSubsystem, scope: nil) {
logger.debug("Executing \(task.description.forLogging) with priority \(task.priority.rawValue)")
}
currentlyExecutingTasks.append(task)
pendingTasks.removeAll(where: { $0 === task })
Task.detached(priority: task.priority) {
withLoggingSubsystemAndScope(subsystem: taskSchedulerSubsystem, scope: nil) {
logger.debug(
"Execution of \(task.description.forLogging) started with priority \(Task.currentPriority.rawValue)"
)
}
// Await the task's return in a task so that this poker can continue checking if there are more execution
// slots that can be filled with queued tasks.
let finishStatus = await task.execute()
withLoggingSubsystemAndScope(subsystem: taskSchedulerSubsystem, scope: nil) {
logger.debug(
"Execution of \(task.description.forLogging) finished with priority \(Task.currentPriority.rawValue)"
)
}
await self.finalizeTaskExecution(task: task, finishStatus: finishStatus)
}
}
Expand Down