monitor update in background

This commit is contained in:
Dmitry Belyaev 2021-06-07 15:57:48 +03:00
parent 841e7bc68e
commit 47a594dda2
Signed by: b4tman
GPG Key ID: 41A00BF15EA7E5F3
2 changed files with 42 additions and 12 deletions

View File

@ -1,7 +1,7 @@
<template> <template>
<transition name="bounce"> <transition name="bounce">
<div <div
v-if="isApacheNeedRestart || isApacheRestartPending" v-if="isActive"
class=" class="
container container
d-flex d-flex
@ -54,14 +54,44 @@
import { mapGetters, mapActions } from "vuex"; import { mapGetters, mapActions } from "vuex";
export default { export default {
computed: mapGetters([ data: () => ({
is_locked: false,
}),
computed: {
...mapGetters([
"isApacheNeedRestart", "isApacheNeedRestart",
"isApacheRestartPending", "isApacheRestartPending",
"isApacheRestartFlagSent", "isApacheRestartFlagSent",
]), ]),
methods: mapActions(["updateApacheRestartFlag", "fetchApacheRestartFlag"]), isActive() {
async updated() { return this.isApacheNeedRestart || this.isApacheRestartPending;
this.fetchApacheRestartFlag(); },
},
methods: {
...mapActions(["updateApacheRestartFlag", "fetchApacheRestartFlag"]),
async monitor_status() {
if (this.is_locked) return;
this.is_locked = true;
while (this.isActive) {
await new Promise((resolve) => setTimeout(resolve, 2000));
await this.fetchApacheRestartFlag();
}
this.is_locked = false;
},
},
watch: {
"$store.getters.isApacheNeedRestart": function () {
this.monitor_status();
},
"$store.getters.isApacheRestartPending": function () {
this.monitor_status();
},
},
async mounted() {
if (this.isActive) await this.monitor_status();
else await this.fetchApacheRestartFlag();
}, },
}; };
</script> </script>

View File

@ -4,7 +4,7 @@ import config from "@/config.js";
const api_base = config.api; const api_base = config.api;
const pass = (some) => some const pass = () => {};
export default { export default {
state: { state: {
@ -48,7 +48,7 @@ export default {
ctx.commit("setApacheRestartFlag", true); ctx.commit("setApacheRestartFlag", true);
ctx.commit("setApacheRestartFlagSent", true); ctx.commit("setApacheRestartFlagSent", true);
} catch (err) { } catch (err) {
pass() pass();
} }
}, },
}, },