Use /ping to verify online status

This commit is contained in:
Matthias 2020-07-26 13:59:01 +02:00
parent 9edf2e9e02
commit 6f54864295
2 changed files with 22 additions and 2 deletions

View File

@ -43,20 +43,37 @@
<script lang="ts">
import { Component, Vue } from 'vue-property-decorator';
import LoginModal from '@/views/LoginModal.vue';
import { State, Mutation } from 'vuex-class';
import { State, Mutation, Action, namespace } from 'vuex-class';
import userService from '@/shared/userService';
import BootswatchThemeSelect from '@/components/BootswatchThemeSelect.vue';
const ftbot = namespace('ftbot');
@Component({
components: { LoginModal, BootswatchThemeSelect },
})
export default class NavBar extends Vue {
pingInterval: NodeJS.Timer | null = null;
@State loggedIn!: boolean;
@State isBotOnline!: boolean;
@Mutation setLoggedIn;
@ftbot.Action ping;
mounted() {
this.ping();
this.pingInterval = setInterval(this.ping, 60000);
}
beforeDestroy() {
if (this.pingInterval) {
clearInterval(this.pingInterval);
}
}
logout(): void {
userService.logout();
this.setLoggedIn(false);

View File

@ -71,7 +71,10 @@ export default {
ping({ commit }) {
api
.get('/ping')
.then((result) => commit('setPing', result.data))
.then((result) => {
commit('setPing', result.data, { root: true });
commit('setIsBotOnline', result.data, { root: true });
})
.catch(console.error);
},
getTrades({ commit }) {