Keep scheduled execution job on text edit (#6354)

close #6346

Changelog:
- fix: keep scheduled execution job in the queue when applying a text edit
This commit is contained in:
Dmitry Bushev 2023-04-19 15:18:36 +01:00 committed by GitHub
parent f288198b4b
commit 8c9c2d79cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 7 deletions

View File

@ -27,10 +27,13 @@ class EditFileCmd(request: Api.EditFileNotification) extends Command(None) {
val edits =
request.edits.map(edit => PendingEdit.ApplyEdit(edit, request.execute))
ctx.state.pendingEdits.enqueue(request.path, edits)
ctx.jobControlPlane.abortAllJobs()
ctx.jobProcessor.run(new EnsureCompiledJob(Seq(request.path)))
if (request.execute) {
ctx.jobControlPlane.abortAllJobs()
ctx.jobProcessor.run(new EnsureCompiledJob(Seq(request.path)))
executeJobs.foreach(ctx.jobProcessor.run)
} else {
ctx.jobControlPlane.abortAllExcept(classOf[ExecuteJob])
ctx.jobProcessor.run(new EnsureCompiledJob(Seq(request.path)))
}
Future.successful(())
} finally {

View File

@ -1,15 +1,22 @@
package org.enso.interpreter.instrument.execution
import org.enso.interpreter.instrument.job.Job
import java.util.UUID
/** Controls running jobs.
*/
trait JobControlPlane {
/** Aborts all interruptible jobs.
*/
/** Aborts all interruptible jobs. */
def abortAllJobs(): Unit
/** Abort all jobs except the ignored jobs.
*
* @param ignoredJobs the list of jobs to keep in the execution queue
*/
def abortAllExcept(ignoredJobs: Class[_ <: Job[_]]*): Unit
/** Aborts all jobs that relates to the specified execution context.
*
* @param contextId an identifier of a context

View File

@ -128,9 +128,17 @@ final class JobExecutionEngine(
}
/** @inheritdoc */
override def abortAllJobs(): Unit = {
val allJobs = runningJobsRef.updateAndGet(_.filterNot(_.future.isCancelled))
val cancellableJobs = allJobs.filter(_.job.isCancellable)
override def abortAllJobs(): Unit =
abortAllExcept()
/** @inheritdoc */
override def abortAllExcept(ignoredJobs: Class[_ <: Job[_]]*): Unit = {
val allJobs = runningJobsRef.updateAndGet(_.filterNot(_.future.isCancelled))
val cancellableJobs = allJobs
.filter { runningJob =>
runningJob.job.isCancellable &&
!ignoredJobs.contains(runningJob.job.getClass)
}
cancellableJobs.foreach { runningJob =>
runningJob.future.cancel(runningJob.job.mayInterruptIfRunning)
}