Alexey Velikiy
3 years ago
5 changed files with 85 additions and 11 deletions
@ -0,0 +1,29 @@ |
|||||||
|
<template> |
||||||
|
<div class="analytic-status"> |
||||||
|
analytic status: <strong> {{ status }} </strong> |
||||||
|
</div> |
||||||
|
</template> |
||||||
|
|
||||||
|
<script lang="ts"> |
||||||
|
import { defineComponent } from 'vue'; |
||||||
|
import { getStatusGenerator } from '@/services/analytics.service'; |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export default defineComponent({ |
||||||
|
name: 'AnalyticStatus', |
||||||
|
components: { |
||||||
|
}, |
||||||
|
data: function name() { |
||||||
|
return { |
||||||
|
status: "loading..." |
||||||
|
} |
||||||
|
}, |
||||||
|
mounted: async function() { |
||||||
|
let g = getStatusGenerator(); |
||||||
|
for await (const data of g) { |
||||||
|
this.status = data.toLowerCase(); |
||||||
|
} |
||||||
|
} |
||||||
|
}); |
||||||
|
</script> |
@ -0,0 +1,22 @@ |
|||||||
|
// TODO: https://github.com/hastic/hastic-grafana-app/blob/c67bd8af140105c36f24c875187929869e48e51e/src/panel/graph_panel/services/analytic_service.ts
|
||||||
|
|
||||||
|
import { API_URL } from "@/config"; |
||||||
|
import axios from 'axios'; |
||||||
|
|
||||||
|
import { getGenerator } from '@/utils'; |
||||||
|
|
||||||
|
import _ from 'lodash'; |
||||||
|
|
||||||
|
const ANALYTICS_API_URL = API_URL + "analytics/"; |
||||||
|
|
||||||
|
export async function getStatus(): Promise<string> { |
||||||
|
const uri = ANALYTICS_API_URL + `status`; |
||||||
|
const res = await axios.get(uri); |
||||||
|
const data = res['data'] as any; |
||||||
|
console.log(data.status); |
||||||
|
return data.status; |
||||||
|
} |
||||||
|
|
||||||
|
export function getStatusGenerator(): AsyncIterableIterator<string> { |
||||||
|
return getGenerator<string>(100, getStatus); |
||||||
|
} |
@ -0,0 +1,15 @@ |
|||||||
|
export async function *getGenerator<T>( |
||||||
|
duration: number, |
||||||
|
func: (...args: any[]) => Promise<T>, |
||||||
|
...args |
||||||
|
): AsyncIterableIterator<T> { |
||||||
|
|
||||||
|
let timeout = async () => new Promise( |
||||||
|
resolve => setTimeout(resolve, duration) |
||||||
|
); |
||||||
|
|
||||||
|
while(true) { |
||||||
|
yield await func(...args); |
||||||
|
await timeout(); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue