mirror of https://github.com/portainer/portainer
26 lines
622 B
TypeScript
26 lines
622 B
TypeScript
import { useQuery } from '@tanstack/react-query';
|
|
|
|
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
|
|
|
import { EdgeJob } from '../types';
|
|
|
|
import { buildUrl } from './build-url';
|
|
import { queryKeys } from './query-keys';
|
|
|
|
async function getEdgeJobs() {
|
|
try {
|
|
const { data } = await axios.get<EdgeJob[]>(buildUrl());
|
|
return data;
|
|
} catch (err) {
|
|
throw parseAxiosError(err as Error, 'Failed fetching edge jobs');
|
|
}
|
|
}
|
|
|
|
export function useEdgeJobs<T = EdgeJob[]>({
|
|
select,
|
|
}: {
|
|
select?: (jobs: EdgeJob[]) => T;
|
|
} = {}) {
|
|
return useQuery(queryKeys.base(), getEdgeJobs, { select });
|
|
}
|