Skip to content

Commit

Permalink
Use setTimeout instead of setInterval
Browse files Browse the repository at this point in the history
- auto-refresh user samples table every 20secs
- auto-refresh admin samples and jobs tables every 30secs
- resolves #42
  • Loading branch information
lkeegan committed Nov 6, 2024
1 parent fdcaf91 commit 01d3a1d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
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 @@ update_samples();
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

0 comments on commit 01d3a1d

Please sign in to comment.