File size: 3,114 Bytes
8ede856
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<template>
    <v-dialog v-model="visible" persistent max-width="400">
        <v-card>
            <v-card-title>{{ t('core.common.restart.waiting') }}</v-card-title>
            <v-card-text>
                <v-progress-linear indeterminate color="primary"></v-progress-linear>
            </v-card-text>
        </v-card>
    </v-dialog>
</template>

<script>
import axios from 'axios'
import { useCommonStore } from '@/stores/common';
import { useI18n } from '@/i18n/composables';


export default {
    name: 'WaitingForRestart',
    setup() {
        const { t } = useI18n();
        return { t };
    },
    data() {
        return {
            visible: false,
            startTime: -1,
            newStartTime: -1,
            status: '',
            cnt: 0,
        }
    },
    methods: {
        async check(initialStartTime = null) {
            this.newStartTime = -1
            this.cnt = 0
            this.visible = true
            this.status = ""
            if (typeof initialStartTime === 'number' && Number.isFinite(initialStartTime)) {
                this.startTime = initialStartTime
            } else {
                const commonStore = useCommonStore()
                try {
                    this.startTime = await commonStore.fetchStartTime()
                } catch (_error) {
                    this.startTime = commonStore.getStartTime()
                }
            }
            console.log('start wfr')
            setTimeout(() => {
                this.timeoutInternal()
            }, 1000)
        },
        stop() {
            this.visible = false
            this.cnt = 0
            this.newStartTime = -1
        },
        timeoutInternal() {
            console.log('wfr: timeoutInternal', this.newStartTime, this.startTime)
            if (this.newStartTime === -1 && this.cnt < 60 && this.visible) {
                this.checkStartTime()
                this.cnt++
                setTimeout(() => {
                    this.timeoutInternal()
                }, 1000)
            } else {
                if (this.cnt >= 60) {
                    this.status = this.t('core.common.restart.maxRetriesReached')
                }
                this.cnt = 0
                setTimeout(() => {
                    this.visible = false
                }, 1000)
            }
        },
        async checkStartTime() {
            try {
                let res = await axios.get('/api/stat/start-time', { timeout: 3000 })
                let newStartTime = res.data.data.start_time
                console.log('wfr: checkStartTime', newStartTime, this.startTime)
                if (this.startTime !== -1 && newStartTime !== this.startTime) {
                    this.newStartTime = newStartTime
                    console.log('wfr: restarted')
                    this.visible = false
                    // reload
                    window.location.reload()
                }
            } catch (_error) {
                // backend may be unavailable during restart window
            }
            return this.newStartTime
        }
    }
}
</script>