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 = val edits =
request.edits.map(edit => PendingEdit.ApplyEdit(edit, request.execute)) request.edits.map(edit => PendingEdit.ApplyEdit(edit, request.execute))
ctx.state.pendingEdits.enqueue(request.path, edits) ctx.state.pendingEdits.enqueue(request.path, edits)
if (request.execute) {
ctx.jobControlPlane.abortAllJobs() ctx.jobControlPlane.abortAllJobs()
ctx.jobProcessor.run(new EnsureCompiledJob(Seq(request.path))) ctx.jobProcessor.run(new EnsureCompiledJob(Seq(request.path)))
if (request.execute) {
executeJobs.foreach(ctx.jobProcessor.run) executeJobs.foreach(ctx.jobProcessor.run)
} else {
ctx.jobControlPlane.abortAllExcept(classOf[ExecuteJob])
ctx.jobProcessor.run(new EnsureCompiledJob(Seq(request.path)))
} }
Future.successful(()) Future.successful(())
} finally { } finally {

View File

@ -1,15 +1,22 @@
package org.enso.interpreter.instrument.execution package org.enso.interpreter.instrument.execution
import org.enso.interpreter.instrument.job.Job
import java.util.UUID import java.util.UUID
/** Controls running jobs. /** Controls running jobs.
*/ */
trait JobControlPlane { trait JobControlPlane {
/** Aborts all interruptible jobs. /** Aborts all interruptible jobs. */
*/
def abortAllJobs(): Unit 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. /** Aborts all jobs that relates to the specified execution context.
* *
* @param contextId an identifier of a context * @param contextId an identifier of a context

View File

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