Allow running tasks to be resumed
This commit is contained in:
parent
5feba6ad26
commit
ac382b7fab
1 changed files with 43 additions and 11 deletions
|
|
@ -1,5 +1,8 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="uk-margin-remove uk-padding-remove">
|
<div
|
||||||
|
v-observe-visibility="visibilityChanged"
|
||||||
|
class="uk-margin-remove uk-padding-remove"
|
||||||
|
>
|
||||||
<div v-if="taskStarted" ref="isPollingElement">
|
<div v-if="taskStarted" ref="isPollingElement">
|
||||||
<div class="progress uk-margin-small">
|
<div class="progress uk-margin-small">
|
||||||
<div
|
<div
|
||||||
|
|
@ -109,7 +112,11 @@ export default {
|
||||||
created() {},
|
created() {},
|
||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
// A global signal listener to perform a move action
|
// Check for already running tasks
|
||||||
|
if (this.taskStarted != true) {
|
||||||
|
this.checkExistingTasks();
|
||||||
|
}
|
||||||
|
// A global signal listener to perform the action
|
||||||
if (this.submitOnEvent) {
|
if (this.submitOnEvent) {
|
||||||
this.$root.$on(this.submitOnEvent, () => {
|
this.$root.$on(this.submitOnEvent, () => {
|
||||||
this.bootstrapTask();
|
this.bootstrapTask();
|
||||||
|
|
@ -124,7 +131,27 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
|
visibilityChanged(isVisible) {
|
||||||
|
if (isVisible && this.taskStarted != true) {
|
||||||
|
this.checkExistingTasks();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
checkExistingTasks: function() {
|
||||||
|
axios.get(this.submitUrl).then(response => {
|
||||||
|
console.log(response.data);
|
||||||
|
for (const task of response.data) {
|
||||||
|
if (task.status == "pending" || task.status == "running") {
|
||||||
|
this.taskStarted = true;
|
||||||
|
this.$emit("taskStarted", this.taskId);
|
||||||
|
this.startPolling(task.id, task.links.self.href);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
bootstrapTask: function() {
|
bootstrapTask: function() {
|
||||||
|
// Starts the process of creating a new Actiont ask
|
||||||
if (this.requiresConfirmation) {
|
if (this.requiresConfirmation) {
|
||||||
this.modalConfirm(this.confirmationMessage).then(
|
this.modalConfirm(this.confirmationMessage).then(
|
||||||
() => {
|
() => {
|
||||||
|
|
@ -138,6 +165,7 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
startTask: function() {
|
startTask: function() {
|
||||||
|
// Starts a new Action task
|
||||||
console.log("Task start clicked");
|
console.log("Task start clicked");
|
||||||
this.$emit("submit", this.submitData);
|
this.$emit("submit", this.submitData);
|
||||||
// Send a request to start a task
|
// Send a request to start a task
|
||||||
|
|
@ -148,16 +176,19 @@ export default {
|
||||||
.post(this.submitUrl, this.submitData)
|
.post(this.submitUrl, this.submitData)
|
||||||
// Get the returned Task ID
|
// Get the returned Task ID
|
||||||
.then(response => {
|
.then(response => {
|
||||||
// Fetch the task ID
|
|
||||||
console.log("Task ID: " + response.data.id);
|
|
||||||
this.taskId = response.data.id;
|
|
||||||
this.taskUrl = response.data.href;
|
|
||||||
// Start the store polling TaskId for success
|
// Start the store polling TaskId for success
|
||||||
this.taskRunning = true;
|
this.startPolling(response.data.id, response.data.href);
|
||||||
this.$emit("taskRunning", this.taskId);
|
});
|
||||||
// Return the poll-task promise (starts polling the task)
|
},
|
||||||
return this.pollTask(this.taskId, this.pollInterval);
|
|
||||||
})
|
startPolling: function(taskId, taskUrl) {
|
||||||
|
// Starts polling an existing Action task
|
||||||
|
this.taskId = taskId;
|
||||||
|
this.taskUrl = taskUrl;
|
||||||
|
// Start the store polling TaskId for success
|
||||||
|
this.taskRunning = true;
|
||||||
|
this.$emit("taskRunning", this.taskId);
|
||||||
|
this.pollTask(this.taskId, this.pollInterval)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
// Do something with the final response
|
// Do something with the final response
|
||||||
console.log("Emitting onResponse: ", response);
|
console.log("Emitting onResponse: ", response);
|
||||||
|
|
@ -230,6 +261,7 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
terminateTask: function() {
|
terminateTask: function() {
|
||||||
|
console.log("Terminating task...");
|
||||||
axios.delete(this.taskUrl).then(response => {
|
axios.delete(this.taskUrl).then(response => {
|
||||||
console.log("TERMINATION RESPONSE: ", response.data);
|
console.log("TERMINATION RESPONSE: ", response.data);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue