Skip to content

Commit

Permalink
Merge pull request #53 from mitre/fix/operation_data_network_usage
Browse files Browse the repository at this point in the history
Refactored operation polling to only request active operation
  • Loading branch information
elegantmoose authored Jun 7, 2024
2 parents b5f7315 + fd87628 commit 478744c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/stores/operationStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ export const useOperationStore = defineStore("operationStore", {
console.error("Error fetching operations", error);
}
},
async getOperation($api, operationID) {
try {
const response = await $api.get(`/api/v2/operations/${operationID}`);
let operation = response.data;
this.operations[operation.id] = operation;
} catch (error) {
console.error("Error fetching operations", error);
}
},
async createOperation($api, operation) {
try {
const response = await $api.post("/api/v2/operations", operation);
Expand Down
7 changes: 4 additions & 3 deletions src/views/OperationsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,14 @@ const resetFilter = () => {
};
function selectOperation() {
//TODO: Stop updating if operation is finished
if (updateInterval) clearInterval(updateInterval);
if (operationStore.selectedOperationID === "") return;
resetFilter();
updateInterval = setInterval(async () => {
if (operationStore.selectedOperationID !== "") {
await operationStore.getOperations($api);
if (operationStore.selectedOperationID !== "" &&
operationStore.operations[operationStore.selectedOperationID].state !== "finished")
{
await operationStore.getOperation($api, operationStore.selectedOperationID);
} else {
clearInterval(updateInterval);
}
Expand Down

0 comments on commit 478744c

Please sign in to comment.