mirror of
https://github.com/portainer/portainer.git
synced 2025-07-24 15:59:41 +02:00
feat(kubernetes): support for jobs and cron jobs - r8s-182 (#260)
Co-authored-by: James Carppe <85850129+jamescarppe@users.noreply.github.com> Co-authored-by: Anthony Lapenna <anthony.lapenna@portainer.io> Co-authored-by: andres-portainer <91705312+andres-portainer@users.noreply.github.com> Co-authored-by: Oscar Zhou <100548325+oscarzhou-portainer@users.noreply.github.com> Co-authored-by: Yajith Dayarathna <yajith.dayarathna@portainer.io> Co-authored-by: LP B <xAt0mZ@users.noreply.github.com> Co-authored-by: oscarzhou <oscar.zhou@portainer.io> Co-authored-by: testA113 <aliharriss1995@gmail.com>
This commit is contained in:
parent
24fdb1f600
commit
d32b0f8b7e
51 changed files with 1786 additions and 22 deletions
|
@ -0,0 +1,6 @@
|
|||
import { EnvironmentId } from '@/react/portainer/environments/types';
|
||||
|
||||
export const queryKeys = {
|
||||
list: (environmentId: EnvironmentId) =>
|
||||
['environments', environmentId, 'kubernetes', 'jobs'] as const,
|
||||
};
|
|
@ -0,0 +1,31 @@
|
|||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
|
||||
import { withGlobalError, withInvalidate } from '@/react-tools/react-query';
|
||||
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
||||
import { EnvironmentId } from '@/react/portainer/environments/types';
|
||||
|
||||
import { queryKeys } from './query-keys';
|
||||
|
||||
export function useDeleteJobsMutation(environmentId: EnvironmentId) {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation(deleteJob, {
|
||||
...withInvalidate(queryClient, [queryKeys.list(environmentId)]),
|
||||
...withGlobalError('Unable to delete Jobs'),
|
||||
});
|
||||
}
|
||||
|
||||
type NamespaceJobsMap = Record<string, string[]>;
|
||||
|
||||
export async function deleteJob({
|
||||
environmentId,
|
||||
data,
|
||||
}: {
|
||||
environmentId: EnvironmentId;
|
||||
data: NamespaceJobsMap;
|
||||
}) {
|
||||
try {
|
||||
return await axios.post(`kubernetes/${environmentId}/jobs/delete`, data);
|
||||
} catch (e) {
|
||||
throw parseAxiosError(e, `Unable to delete Jobs`);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
import { withGlobalError } from '@/react-tools/react-query';
|
||||
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
||||
import { EnvironmentId } from '@/react/portainer/environments/types';
|
||||
|
||||
import { Job } from '../types';
|
||||
|
||||
import { queryKeys } from './query-keys';
|
||||
|
||||
export function useJobs(
|
||||
environmentId: EnvironmentId,
|
||||
options?: { refetchInterval?: number; enabled?: boolean }
|
||||
) {
|
||||
return useQuery(
|
||||
queryKeys.list(environmentId),
|
||||
async () => getAllJobs(environmentId),
|
||||
{
|
||||
...withGlobalError('Unable to get Jobs'),
|
||||
refetchInterval() {
|
||||
return options?.refetchInterval ?? false;
|
||||
},
|
||||
enabled: options?.enabled,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
async function getAllJobs(environmentId: EnvironmentId) {
|
||||
try {
|
||||
const { data: jobs } = await axios.get<Job[]>(
|
||||
`kubernetes/${environmentId}/jobs`
|
||||
);
|
||||
|
||||
return jobs;
|
||||
} catch (e) {
|
||||
throw parseAxiosError(e, 'Unable to get Jobs');
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue