feat(ui): fetch all flux tasks
parent
23e60b2400
commit
b0ef6421d8
|
@ -108,13 +108,14 @@ export const fetchRules = kapacitor => async dispatch => {
|
|||
|
||||
export const fetchFluxTasks = kapacitor => async dispatch => {
|
||||
try {
|
||||
const {
|
||||
data: {tasks},
|
||||
} = await getFluxTasks(kapacitor)
|
||||
const tasks = await getFluxTasks(kapacitor)
|
||||
dispatch({type: 'LOAD_FLUX_TASKS', payload: {tasks}})
|
||||
} catch (error) {
|
||||
dispatch({type: 'LOAD_FLUX_TASKS', payload: {tasks: null}})
|
||||
dispatch(errorThrown(error))
|
||||
// dispatch an error unless flux tasks are disabled/not supported
|
||||
if (error.status !== 404) {
|
||||
dispatch(errorThrown(error))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import AJAX from 'utils/ajax'
|
||||
import {cloneDeep, get} from 'lodash'
|
||||
import {cloneDeep, get, values} from 'lodash'
|
||||
|
||||
const outRule = rule => {
|
||||
// fit into range
|
||||
|
@ -66,11 +66,35 @@ export const getRules = kapacitor => {
|
|||
})
|
||||
}
|
||||
|
||||
export const getFluxTasks = kapacitor => {
|
||||
return AJAX({
|
||||
method: 'GET',
|
||||
url: kapacitor.links.proxy + '?path=/kapacitor/v1/api/v2/tasks?limit=500',
|
||||
})
|
||||
export const getFluxTasks = async kapacitor => {
|
||||
const taskIds = {}
|
||||
let lastID = ''
|
||||
for (;;) {
|
||||
const {
|
||||
data: {tasks},
|
||||
} = await AJAX({
|
||||
method: 'GET',
|
||||
url:
|
||||
kapacitor.links.proxy +
|
||||
`?path=/kapacitor/v1/api/v2/tasks?limit=500&after=${lastID}`,
|
||||
})
|
||||
if (!tasks || !tasks.length) {
|
||||
break
|
||||
}
|
||||
lastID = tasks[tasks.length - 1].id
|
||||
let noNewData = true
|
||||
tasks.forEach(x => {
|
||||
if (taskIds[x.id]) {
|
||||
return
|
||||
}
|
||||
noNewData = false
|
||||
taskIds[x.id] = x
|
||||
})
|
||||
if (noNewData) {
|
||||
break
|
||||
}
|
||||
}
|
||||
return values(taskIds).sort((a, b) => a.name.localeCompare(b.name))
|
||||
}
|
||||
|
||||
export const getRule = async (kapacitor, ruleID) => {
|
||||
|
|
|
@ -181,7 +181,6 @@ export class KapacitorRulesPage extends PureComponent<Props, State> {
|
|||
await this.props.fetchFluxTasks(kapacitor)
|
||||
await pingKapacitor(kapacitor)
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
this.props.notify(notifyKapacitorConnectionFailed())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue