Fix end of action behaviours and looging errors
This commit is contained in:
parent
dd0a57520b
commit
8b785823ab
2 changed files with 21 additions and 55 deletions
|
|
@ -156,27 +156,6 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
//Define .from_index() as a custom function, working similar to .at()
|
|
||||||
//For backwards compatibility, not using in-built .at() until updates to Connect
|
|
||||||
function from_index(n) {
|
|
||||||
// ToInteger() abstract op
|
|
||||||
n = Math.trunc(n) || 0;
|
|
||||||
// Allow negative indexing from the end
|
|
||||||
if (n < 0) n += this.length;
|
|
||||||
// Out of bounds access is guaranteed to return undefined
|
|
||||||
if (n < 0 || n >= this.length) return undefined;
|
|
||||||
// Otherwise, this is just normal property access
|
|
||||||
return this[n];
|
|
||||||
}
|
|
||||||
const TypedArray = Reflect.getPrototypeOf(Int8Array);
|
|
||||||
for (const C of [Array, String, TypedArray]) {
|
|
||||||
Object.defineProperty(C.prototype, "from_index", {
|
|
||||||
value: from_index,
|
|
||||||
writable: true,
|
|
||||||
enumerable: false,
|
|
||||||
configurable: true,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
// Check for already running tasks
|
// Check for already running tasks
|
||||||
if (this.taskStarted != true) {
|
if (this.taskStarted != true) {
|
||||||
this.checkExistingTasks();
|
this.checkExistingTasks();
|
||||||
|
|
@ -282,7 +261,6 @@ export default {
|
||||||
this.onPollingResponse,
|
this.onPollingResponse,
|
||||||
this.onTaskEnd, // Method to run after task (even if error)
|
this.onTaskEnd, // Method to run after task (even if error)
|
||||||
500, // Interval
|
500, // Interval
|
||||||
false, // Don't handle errors,
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -305,40 +283,12 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
onPollingResponse(response) {
|
onPollingResponse(response) {
|
||||||
|
// While the task is still running, we update progress/log,
|
||||||
|
// and schedule another poll
|
||||||
var result = response.data.status;
|
var result = response.data.status;
|
||||||
this.taskStatus = result;
|
this.taskStatus = result;
|
||||||
if ((result == "running") | (result == "pending")) {
|
this.progress = response.data.progress;
|
||||||
// If the task is still running, we update progress/log,
|
this.log = response.data.log;
|
||||||
// and schedule another poll
|
|
||||||
this.progress = response.data.progress;
|
|
||||||
this.log = response.data.log;
|
|
||||||
}
|
|
||||||
// If task ends with an error
|
|
||||||
else if (result == "error") {
|
|
||||||
this.handleErrorResponse(response);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
handleErrorResponse(response) {
|
|
||||||
// Pass the error string back with reject
|
|
||||||
if (!this.progress) this.progress = 1;
|
|
||||||
// Test whether the log is empty or the most recent message is not from an error
|
|
||||||
// If so, return a default message
|
|
||||||
if (
|
|
||||||
(response.data.log.length == 0) |
|
|
||||||
(response.data.log.from_index(-1).levelname != "ERROR")
|
|
||||||
) {
|
|
||||||
var message = "Unexpected error, please check the logs";
|
|
||||||
}
|
|
||||||
// As LabThings Actions add the message from any raised exception to the log, the
|
|
||||||
// last message in the log is the message from the Exception.
|
|
||||||
// If the Exception was raised with no message, use a default.
|
|
||||||
else {
|
|
||||||
message =
|
|
||||||
response.data.log.from_index(-1).message || "Unexpected error, please check the logs";
|
|
||||||
}
|
|
||||||
// Raise an Error with the chosen message
|
|
||||||
throw new Error(message);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
terminateTask: function () {
|
terminateTask: function () {
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,8 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="taskStatus == 'error'" class="uk-alert uk-alert-danger">
|
<div v-if="taskStatus == 'error'" class="uk-alert uk-alert-danger">
|
||||||
The task failed due to an error. There may be more information in the log.
|
<p><b>The task failed due to an error:</b></p>
|
||||||
|
<p>{{ errorMessage }}</p>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="taskStatus == 'cancelled'" class="uk-alert uk-alert-warning">
|
<div v-if="taskStatus == 'cancelled'" class="uk-alert uk-alert-warning">
|
||||||
The task was cancelled.
|
The task was cancelled.
|
||||||
|
|
@ -43,6 +44,21 @@ export default {
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
computed: {
|
||||||
|
errorMessage() {
|
||||||
|
let logLength = this.log.length;
|
||||||
|
var defaultMessage = "Unexpected error, please check the logs";
|
||||||
|
if (logLength == 0) {
|
||||||
|
return defaultMessage;
|
||||||
|
}
|
||||||
|
// Cannot use .at until we update OpenFlexure Connect
|
||||||
|
if (this.log[logLength - 1].levelname != "ERROR") {
|
||||||
|
return defaultMessage;
|
||||||
|
}
|
||||||
|
return this.log[logLength - 1].message || defaultMessage;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
watch: {
|
watch: {
|
||||||
log: function () {
|
log: function () {
|
||||||
this.scrollToBottom();
|
this.scrollToBottom();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue