Skip to content

Commit e3d0eeb

Browse files
ping task if is_running
useFetch in do_ping instead of api_fetch
1 parent 1fbb6ad commit e3d0eeb

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

stores/geode.js

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,32 +32,39 @@ export const use_geode_store = defineStore("geode", {
3232
}
3333
return geode_url
3434
},
35-
is_busy(state) {
36-
return state.request_counter > 0
35+
is_busy() {
36+
return this.request_counter > 0
3737
},
3838
},
3939
actions: {
4040
ping_task() {
41-
setInterval(() => this.do_ping(), 10 * 1000)
41+
setInterval(() => {
42+
if (this.is_running) {
43+
this.do_ping()
44+
}
45+
}, 10 * 1000)
4246
},
4347
async do_ping() {
4448
const feedback_store = use_feedback_store()
45-
await api_fetch(
46-
{ schema: back_schemas.opengeodeweb_back.ping, params: {} },
47-
{
48-
request_error_function: async () => {
49+
return new Promise(async (resolve, reject) => {
50+
useFetch(back_schemas.opengeodeweb_back.ping.$id, {
51+
baseURL: this.base_url,
52+
method: back_schemas.opengeodeweb_back.ping.methods[0],
53+
async onRequestError() {
4954
await feedback_store.$patch({ server_error: true })
5055
this.is_running = false
56+
reject()
5157
},
52-
response_function: async () => {
53-
this.is_running = true
58+
async onResponse() {
59+
resolve()
5460
},
55-
response_error_function: async () => {
61+
async onResponseError() {
5662
await feedback_store.$patch({ server_error: true })
5763
this.is_running = false
64+
reject()
5865
},
59-
},
60-
)
66+
})
67+
})
6168
},
6269
start_request() {
6370
this.request_counter++

0 commit comments

Comments
 (0)