From 8c9c2d79cd6c3c21bf5b7665c6b28af20006c950 Mon Sep 17 00:00:00 2001 From: Dmitry Bushev Date: Wed, 19 Apr 2023 15:18:36 +0100 Subject: [PATCH] Keep scheduled execution job on text edit (#6354) close #6346 Changelog: - fix: keep scheduled execution job in the queue when applying a text edit --- .../instrument/command/EditFileCmd.scala | 7 +++++-- .../instrument/execution/JobControlPlane.scala | 11 +++++++++-- .../instrument/execution/JobExecutionEngine.scala | 14 +++++++++++--- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/engine/runtime/src/main/scala/org/enso/interpreter/instrument/command/EditFileCmd.scala b/engine/runtime/src/main/scala/org/enso/interpreter/instrument/command/EditFileCmd.scala index b2809d9b8f..7591ae254f 100644 --- a/engine/runtime/src/main/scala/org/enso/interpreter/instrument/command/EditFileCmd.scala +++ b/engine/runtime/src/main/scala/org/enso/interpreter/instrument/command/EditFileCmd.scala @@ -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 { diff --git a/engine/runtime/src/main/scala/org/enso/interpreter/instrument/execution/JobControlPlane.scala b/engine/runtime/src/main/scala/org/enso/interpreter/instrument/execution/JobControlPlane.scala index 5464cc8384..c3b17d0482 100644 --- a/engine/runtime/src/main/scala/org/enso/interpreter/instrument/execution/JobControlPlane.scala +++ b/engine/runtime/src/main/scala/org/enso/interpreter/instrument/execution/JobControlPlane.scala @@ -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 diff --git a/engine/runtime/src/main/scala/org/enso/interpreter/instrument/execution/JobExecutionEngine.scala b/engine/runtime/src/main/scala/org/enso/interpreter/instrument/execution/JobExecutionEngine.scala index 9af78f739b..e36953b1ec 100644 --- a/engine/runtime/src/main/scala/org/enso/interpreter/instrument/execution/JobExecutionEngine.scala +++ b/engine/runtime/src/main/scala/org/enso/interpreter/instrument/execution/JobExecutionEngine.scala @@ -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) }