Skip to content
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

[Interpreter] Make interpreter execution cancellable #39962

Closed
lukasolson opened this issue Jun 28, 2019 · 6 comments
Closed

[Interpreter] Make interpreter execution cancellable #39962

lukasolson opened this issue Jun 28, 2019 · 6 comments
Labels
Feature:ExpressionLanguage Interpreter expression language (aka canvas pipeline)

Comments

@lukasolson
Copy link
Member

We need a way to "cancel" the execution of the interpreter under certain scenarios. This might be because a user has navigated away from a page, or because a new execution context is being requested to run that will replace the current execution.

For example, if a user has a visualization embedded on a dashboard, changes the query, and then submits, there is no reason to continue the execution of the current chain, as it will be replaced anyway.

I propose adding something similar to an AbortSignal to the expression runner options. Then, inside the interpreter, before executing each function, we can check if the signal has been aborted before executing the function. We'll also have to pass this signal into functions themselves (maybe inside the handlers) so that they can actively handle cancelling anything currently in progress (such as a request).

/cc @ppisljar @lukeelmers

@lukasolson lukasolson added Feature:ExpressionLanguage Interpreter expression language (aka canvas pipeline) Team:AppArch labels Jun 28, 2019
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app-arch

@ppisljar
Copy link
Member

ppisljar commented Jul 1, 2019

/cc @timroes

agreed, this is part of functionality that is still missing as far as i am aware, and i like your proposition of using abort signal.

@lukeelmers
Copy link
Member

++ This approach makes sense to me.

So basically:

const controller = new AbortController();
await data.expressions.run('foo | bar', { signal: controller.signal });

And in your interpreter functions:

async fn(context, args, { signal }) {
  signal.addEventListener('abort', () => console.log('cleanup'));
}

Or I suppose you could alternatively expose the abort event as an observable in the handler.

@ppisljar
Copy link
Member

ppisljar commented Jul 2, 2019

most functons shouldn't need to implement this, interpreter should handle this on its own (if abort signal fired then it should quit after currenty executing function terminates.

functions would use this in advanced use cases (for example esaggs function would be passing this abort signal to kfetch (or whatever)

@timroes
Copy link
Contributor

timroes commented Jul 2, 2019

Despite the fact, that I think we should not use EventEmitters, because they are not properly typeable, but instead should reach in some proper oberservables for the individual signals, I think the functionality of this is rather good, because as Peter mentioned most functions most likely won't need some special handling for that.

@lukasolson
Copy link
Member Author

Resolved by #40238.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:ExpressionLanguage Interpreter expression language (aka canvas pipeline)
Projects
None yet
Development

No branches or pull requests

5 participants