|
|
@@ -56,7 +56,7 @@
|
|
|
|
|
|
<script lang="ts">
|
|
|
import { EXECUTABLE_UPDATED_TOPIC, ExecutableUpdatedEvent } from 'apps/editor/execution/events';
|
|
|
- import { defineComponent, PropType, ref, toRefs, watch } from 'vue';
|
|
|
+ import { defineComponent, nextTick, PropType, ref, toRefs, watch } from 'vue';
|
|
|
|
|
|
import SqlExecutable from 'apps/editor/execution/sqlExecutable';
|
|
|
import HueButton from 'components/HueButton.vue';
|
|
|
@@ -67,8 +67,8 @@
|
|
|
import { Session } from 'apps/editor/execution/api';
|
|
|
import { ExecutionStatus } from 'apps/editor/execution/executable';
|
|
|
import sessionManager from 'apps/editor/execution/sessionManager';
|
|
|
+ import { EXECUTE_ACTIVE_EXECUTABLE_TOPIC, ExecuteActiveExecutableEvent } from './events';
|
|
|
|
|
|
- const EXECUTE_ACTIVE_EXECUTABLE_EVENT = 'executable.active.executable';
|
|
|
const WHITE_SPACE_REGEX = /^\s*$/;
|
|
|
|
|
|
export default defineComponent({
|
|
|
@@ -86,7 +86,8 @@
|
|
|
default: undefined
|
|
|
}
|
|
|
},
|
|
|
- setup(props) {
|
|
|
+ emits: ['execute-started', 'executable-updated', 'execute-stopping'],
|
|
|
+ setup(props, { emit }) {
|
|
|
const { executable, beforeExecute } = toRefs(props);
|
|
|
const subTracker = new SubscriptionTracker();
|
|
|
|
|
|
@@ -107,9 +108,20 @@
|
|
|
await beforeExecute.value(executable.value as SqlExecutable);
|
|
|
}
|
|
|
await executable.value.reset();
|
|
|
+ emit('execute-started', executable.value);
|
|
|
executable.value.execute();
|
|
|
};
|
|
|
|
|
|
+ const stop = async (): Promise<void> => {
|
|
|
+ if (stopping.value || !executable.value) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ emit('execute-stopping', executable.value);
|
|
|
+ stopping.value = true;
|
|
|
+ await executable.value.cancelBatchChain(true);
|
|
|
+ stopping.value = false;
|
|
|
+ };
|
|
|
+
|
|
|
const updateFromExecutable = (executable: SqlExecutable): void => {
|
|
|
const waitForSession =
|
|
|
!lastSession || lastSession.type !== executable.executor.connector().type;
|
|
|
@@ -139,19 +151,26 @@
|
|
|
);
|
|
|
|
|
|
subTracker.subscribe<ExecutableUpdatedEvent>(EXECUTABLE_UPDATED_TOPIC, updatedExecutable => {
|
|
|
- if (executable.value && executable.value.id === updatedExecutable.id) {
|
|
|
+ const active = executable.value && executable.value.id === updatedExecutable.id;
|
|
|
+ if (active) {
|
|
|
updateFromExecutable(updatedExecutable);
|
|
|
}
|
|
|
+ emit('executable-updated', { executable: updatedExecutable, active });
|
|
|
});
|
|
|
|
|
|
- subTracker.subscribe(EXECUTE_ACTIVE_EXECUTABLE_EVENT, eventExecutable => {
|
|
|
- if (executable.value && executable.value === eventExecutable) {
|
|
|
- execute();
|
|
|
+ subTracker.subscribe<ExecuteActiveExecutableEvent>(
|
|
|
+ EXECUTE_ACTIVE_EXECUTABLE_TOPIC,
|
|
|
+ async eventExecutable => {
|
|
|
+ if (executable.value && executable.value.id === eventExecutable.id) {
|
|
|
+ await execute();
|
|
|
+ }
|
|
|
}
|
|
|
- });
|
|
|
+ );
|
|
|
|
|
|
return {
|
|
|
+ execute,
|
|
|
subTracker,
|
|
|
+ stop,
|
|
|
stopping,
|
|
|
loadingSession,
|
|
|
partOfRunningExecution,
|
|
|
@@ -183,28 +202,6 @@
|
|
|
this.waiting
|
|
|
);
|
|
|
}
|
|
|
- },
|
|
|
- methods: {
|
|
|
- async execute(): Promise<void> {
|
|
|
- huePubSub.publish('hue.ace.autocompleter.hide');
|
|
|
- if (!this.executable) {
|
|
|
- return;
|
|
|
- }
|
|
|
- if (this.beforeExecute) {
|
|
|
- await this.beforeExecute(this.executable);
|
|
|
- }
|
|
|
- await this.executable.reset();
|
|
|
- this.executable.execute();
|
|
|
- },
|
|
|
-
|
|
|
- async stop(): Promise<void> {
|
|
|
- if (this.stopping || !this.executable) {
|
|
|
- return;
|
|
|
- }
|
|
|
- this.stopping = true;
|
|
|
- await this.executable.cancelBatchChain(true);
|
|
|
- this.stopping = false;
|
|
|
- }
|
|
|
}
|
|
|
});
|
|
|
</script>
|