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>
<transition name="bounce">
<div
v-if="isApacheNeedRestart || isApacheRestartPending"
v-if="isActive"
class="
container
d-flex
@ -54,14 +54,44 @@
import { mapGetters, mapActions } from "vuex";
export default {
computed: mapGetters([
"isApacheNeedRestart",
"isApacheRestartPending",
"isApacheRestartFlagSent",
]),
methods: mapActions(["updateApacheRestartFlag", "fetchApacheRestartFlag"]),
async updated() {
this.fetchApacheRestartFlag();
data: () => ({
is_locked: false,
}),
computed: {
...mapGetters([
"isApacheNeedRestart",
"isApacheRestartPending",
"isApacheRestartFlagSent",
]),
isActive() {
return this.isApacheNeedRestart || this.isApacheRestartPending;
},
},
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>

View File

@ -4,7 +4,7 @@ import config from "@/config.js";
const api_base = config.api;
const pass = (some) => some
const pass = () => {};
export default {
state: {
@ -47,8 +47,8 @@ export default {
await axios.put(`${api_base}/apache-restart`);
ctx.commit("setApacheRestartFlag", true);
ctx.commit("setApacheRestartFlagSent", true);
} catch(err) {
pass()
} catch (err) {
pass();
}
},
},