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

Use setTimeout instead of setInterval #49

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion frontend/src/components/JobsTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from "flowbite-vue";
import type { Job } from "@/utils/types";
import { apiClient, logout } from "@/utils/api-client";
import { ref } from "vue";
import { onUnmounted, ref } from "vue";

const jobs = ref([] as Job[]);

Expand All @@ -29,6 +29,15 @@ function get_jobs() {

get_jobs();

let update_data_handle = setTimeout(function update_data() {
get_jobs();
update_data_handle = setTimeout(update_data, 30000);
});

onUnmounted(() => {
clearTimeout(update_data_handle);
});

function get_runtime_minutes(job: Job): number {
if (job.status === "running") {
return Math.ceil((Date.now() / 1000 - job.timestamp_start) / 60);
Expand Down
11 changes: 10 additions & 1 deletion frontend/src/views/AdminView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import ListComponent from "@/components/ListComponent.vue";
import JobsTable from "@/components/JobsTable.vue";
import ListItem from "@/components/ListItem.vue";
import { FwbButton, FwbTab, FwbTabs } from "flowbite-vue";
import { ref } from "vue";
import { onUnmounted, ref } from "vue";
import type { Sample } from "@/utils/types";
import { apiClient, logout } from "@/utils/api-client";

Expand Down Expand Up @@ -44,6 +44,15 @@ function get_samples() {
}

get_samples();

let update_data_handle = setTimeout(function update_data() {
get_samples();
update_data_handle = setTimeout(update_data, 30000);
});

onUnmounted(() => {
clearTimeout(update_data_handle);
});
</script>

<template>
Expand Down
7 changes: 4 additions & 3 deletions frontend/src/views/SamplesView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,14 @@

const submit_message = ref("");

let update_data = setInterval(() => {
let update_data_handle = setTimeout(function update_data() {
update_samples();
update_submit_message();
}, 30000);
update_data_handle = setTimeout(update_data, 20000);
});

onUnmounted(() => {
clearInterval(update_data);
clearTimeout(update_data_handle);
});

function update_submit_message() {
Expand Down Expand Up @@ -186,7 +187,7 @@
"Content-Type": "multipart/form-data",
},
})
.then((response) => {

Check warning on line 190 in frontend/src/views/SamplesView.vue

View workflow job for this annotation

GitHub Actions / Frontend :: node 22

'response' is defined but never used
update_samples();
update_submit_message();
new_sample_error_message.value = "";
Expand Down
Loading