Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
Poll a particular issue item when IssueDetail is active
天舟bef453e6dac4
diff --git a/frontend/src/store/modules/task.ts b/frontend/src/store/modules/task.tsindex 983ca4e26c..4ad2a91760 100644--- a/frontend/src/store/modules/task.ts+++ b/frontend/src/store/modules/task.ts@@ -118,27 +118,26 @@ const getters = {const actions = {async updateStatus(- { dispatch }: any,+ { rootGetters }: any,{- issueId,pipelineId,taskId,taskStatusPatch,}: {- issueId: IssueId;pipelineId: PipelineId;taskId: TaskId;taskStatusPatch: TaskStatusPatch;}) {- await axios.patch(`/api/pipeline/${pipelineId}/task/${taskId}/status`, {- data: {- type: "taskStatusPatch",- attributes: taskStatusPatch,- },- });-- dispatch("issue/fetchIssueById", issueId, { root: true });+ const data = (+ await axios.patch(`/api/pipeline/${pipelineId}/task/${taskId}/status`, {+ data: {+ type: "taskStatusPatch",+ attributes: taskStatusPatch,+ },+ })+ ).data;+ return convertPartial(data.data, data.included, rootGetters);},};diff --git a/frontend/src/views/IssueDetail.vue b/frontend/src/views/IssueDetail.vueindex 9180d21d7f..d897a9b967 100644--- a/frontend/src/views/IssueDetail.vue+++ b/frontend/src/views/IssueDetail.vue@@ -180,7 +180,15 @@</template><script lang="ts">-import { computed, onMounted, watch, watchEffect, reactive, ref } from "vue";+import {+ computed,+ onMounted,+ onUnmounted,+ watch,+ watchEffect,+ reactive,+ ref,+} from "vue";import { useStore } from "vuex";import { useRouter } from "vue-router";import cloneDeep from "lodash-es/cloneDeep";@@ -229,12 +237,20 @@ import {IssueTemplate,} from "../plugins";+// Normally, we poll issue every 10s to fetch any update from the server side.+// When issue/task status changes we start the poll from 1s, 2s, 4s, 8s, 10s, 10s...+// We do this because issue is more likely to change after we change the status (e.g task finishes running)+const NORMAL_ISSUE_POLL_INTERVAL = 10000;+const POST_STATUS_CHANGE_ISSUE_POLL_INTERVAL = 1000;+interface LocalState {// Needs to maintain this state and set it to false manually after creating the issue.// router.push won't trigger the reload because new and existing issue shares// the same component.create: boolean;newIssue?: IssueCreate;+ // Timer tracking the issue poller, we need this to cancel the outstanding one when needed.+ pollIssueTimer?: ReturnType<typeof setTimeout>;}export default {@@ -260,14 +276,6 @@ export default {const store = useStore();const router = useRouter();- onMounted(() => {- // Always scroll to top, the scrollBehavior doesn't seem to work.- // The hypothesis is that because the scroll bar is in the nested- // route, thus setting the scrollBehavior in the global router- // won't work.- document.getElementById("issue-detail-top")!.scrollIntoView();- });-const currentUser = computed(() => store.getters["auth/currentUser"]());let newIssueTemplate = ref<IssueTemplate>(defaulTemplate());@@ -386,10 +394,43 @@ export default {newIssue: create ? buildNewIssue() : undefined,});+ const pollIssue = (interval: number) => {+ clearInterval(state.pollIssueTimer);+ store.dispatch("issue/fetchIssueById", idFromSlug(props.issueSlug));++ const actualInterval = Math.min(interval * 2, 10000);+ state.pollIssueTimer = setTimeout(() => {+ pollIssue(actualInterval);+ }, actualInterval);+ };++ const pollIssueAfterStatusChange = () => {+ pollIssue(POST_STATUS_CHANGE_ISSUE_POLL_INTERVAL);+ };++ onMounted(() => {+ // Always scroll to top, the scrollBehavior doesn't seem to work.+ // The hypothesis is that because the scroll bar is in the nested+ // route, thus setting the scrollBehavior in the global router+ // won't work.+ document.getElementById("issue-detail-top")!.scrollIntoView();+ if (!state.create) {+ pollIssue(NORMAL_ISSUE_POLL_INTERVAL);+ }+ });++ onUnmounted(() => {+ clearInterval(state.pollIssueTimer);+ });+watch(() => props.issueSlug,(cur, prev) => {+ const oldCreate = state.create;state.create = cur.toLowerCase() == "new";+ if (!state.create && oldCreate) {+ pollIssue(NORMAL_ISSUE_POLL_INTERVAL);+ }});@@ -534,6 +575,7 @@ export default {newState: true,});}+ pollIssueAfterStatusChange();});};@@ -550,12 +592,13 @@ export default {store.dispatch("task/updateStatus", {- issueId: (issue.value as Issue).id,pipelineId: (issue.value as Issue).pipeline.id,taskId,taskStatusPatch,})- .then(() => {});+ .then(() => {+ pollIssueAfterStatusChange();+ });};const patchIssue = (