Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/cancel running job #353

Merged
merged 2 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/api/generated/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export type { AnalogueModelDetail } from './models/AnalogueModelDetail';
export type { AnalogueModelImageDto } from './models/AnalogueModelImageDto';
export type { AnalogueModelList } from './models/AnalogueModelList';
export { AnalogueModelSourceType } from './models/AnalogueModelSourceType';
export type { CancelJobDto } from './models/CancelJobDto';
export type { ComputeCaseComputeMethodDto } from './models/ComputeCaseComputeMethodDto';
export type { ComputeCaseDto } from './models/ComputeCaseDto';
export type { ComputeCaseInputSettingsDto } from './models/ComputeCaseInputSettingsDto';
Expand Down Expand Up @@ -119,6 +120,8 @@ export type { ParameterList } from './models/ParameterList';
export type { PatchAnalogueModelCommandResponse } from './models/PatchAnalogueModelCommandResponse';
export type { PatchAnalogueModelDto } from './models/PatchAnalogueModelDto';
export type { PercentilesDto } from './models/PercentilesDto';
export type { PostCancelJobCommand } from './models/PostCancelJobCommand';
export type { PostCancelJobCommandResponse } from './models/PostCancelJobCommandResponse';
export type { PrepareChunkedUploadCommandResponse } from './models/PrepareChunkedUploadCommandResponse';
export type { PrepareChunkedUploadDto } from './models/PrepareChunkedUploadDto';
export type { ProblemDetails } from './models/ProblemDetails';
Expand Down
15 changes: 15 additions & 0 deletions src/api/generated/models/CancelJobDto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

import type { JobStatus } from './JobStatus';
import type { JobType } from './JobType';

export type CancelJobDto = {
jobId: string;
name: string;
jobStatus: JobStatus;
jobType: JobType;
};

10 changes: 10 additions & 0 deletions src/api/generated/models/PostCancelJobCommand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

export type PostCancelJobCommand = {
modelId: string;
computeCaseId: string;
};

15 changes: 15 additions & 0 deletions src/api/generated/models/PostCancelJobCommandResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

import type { CancelJobDto } from './CancelJobDto';

export type PostCancelJobCommandResponse = {
success?: boolean;
count?: number | null;
message?: string | null;
validationErrors?: Array<string> | null;
data: CancelJobDto;
};

23 changes: 23 additions & 0 deletions src/api/generated/services/JobsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import type { GetCurrentJobStatusCommandResponse } from '../models/GetCurrentJob
import type { GetCurrentJobStatusListCommand } from '../models/GetCurrentJobStatusListCommand';
import type { GetJobDetailQueryResponse } from '../models/GetJobDetailQueryResponse';
import type { GetJobListQueryResponse } from '../models/GetJobListQueryResponse';
import type { PostCancelJobCommand } from '../models/PostCancelJobCommand';
import type { PostCancelJobCommandResponse } from '../models/PostCancelJobCommandResponse';

import type { CancelablePromise } from '../core/CancelablePromise';
import { OpenAPI } from '../core/OpenAPI';
Expand Down Expand Up @@ -95,6 +97,27 @@ export class JobsService {
});
}

/**
* Cancel the running job.
* @param requestBody
* @returns PostCancelJobCommandResponse Accepted
* @throws ApiError
*/
public static postApiJobsCancel(
requestBody?: PostCancelJobCommand,
): CancelablePromise<PostCancelJobCommandResponse> {
return __request(OpenAPI, {
method: 'POST',
url: '/api/jobs/cancel',
body: requestBody,
mediaType: 'application/json-patch+json',
errors: {
403: `Forbidden`,
404: `Not Found`,
},
});
}

/**
* Convert AnalogueModels to the internal format used by PEPM in order to perform calculations.
* @param requestBody
Expand Down
4 changes: 2 additions & 2 deletions src/components/AreaCoordinates/AreaCoordinates.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ export const AreaCoordinates = ({
setEdit(!edit);
};

const handleCancleEdit = () => {
const handleCancelEdit = () => {
fallbackAreaCoordinate &&
setAreaCoordinate(cloneDeep(fallbackAreaCoordinate));

Expand Down Expand Up @@ -352,7 +352,7 @@ export const AreaCoordinates = ({
{edit ? (
<>
<Button onClick={handleSubmit}>Save coordinates</Button>
<Button variant="outlined" onClick={handleCancleEdit}>
<Button variant="outlined" onClick={handleCancelEdit}>
Cancel
</Button>
</>
Expand Down
2 changes: 1 addition & 1 deletion src/components/ConfirmDialog/ConfirmDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const ConfirmDialog = ({
color={danger ? 'danger' : undefined}
onClick={() => setIsOpen(false)}
>
{'Cancle'}
{'Cancel'}
</Button>
<Button color={danger ? 'danger' : undefined} onClick={confirmAction}>
{danger ? 'Delete' : 'Ok'}
Expand Down
12 changes: 7 additions & 5 deletions src/features/Compute/CaseGroup/CaseButtons/CaseButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,22 +146,25 @@ export const CaseButtons = ({
}
>
<Button
color={caseStatus === 'Failed' ? 'danger' : undefined}
color={
caseStatus === 'Failed' || caseStatus === 'Running'
? 'danger'
: undefined
}
variant="outlined"
onClick={saved ? runCase : saveCase}
disabled={
!isProcessed ||
caseStatus === 'Created' ||
caseStatus === 'Waiting' ||
caseStatus === 'Running' ||
!isOwner()
}
>
<Icon data={PLAY} size={18}></Icon>
{caseStatus === 'Created' ||
caseStatus === 'Waiting' ||
caseStatus === 'Running'
? 'Running ... '
? 'Cancel'
: caseStatus === 'Failed'
? 'Re-run'
: 'Run'}
Expand Down Expand Up @@ -206,15 +209,14 @@ export const CaseButtons = ({
id.length < 3 ||
caseStatus === 'Created' ||
caseStatus === 'Waiting' ||
caseStatus === 'Running' ||
!isOwner()
}
>
<Icon data={PLAY} size={18}></Icon>
{caseStatus === 'Created' ||
caseStatus === 'Waiting' ||
caseStatus === 'Running'
? 'Running ... '
? 'Cancel'
: caseStatus === 'Failed'
? 'Re-run'
: 'Run'}
Expand Down
32 changes: 31 additions & 1 deletion src/features/Compute/CaseGroup/CaseRow/CaseRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
import { useState } from 'react';
import {
ComputeCaseDto,
ComputeJobStatus,
CreateComputeCaseCommandResponse,
CreateComputeCaseInputSettingsForm,
JobsService,
ListComputeCasesByAnalogueModelIdQueryResponse,
ListComputeSettingsInputDto,
ListComputeSettingsMethodDto,
PostCancelJobCommand,
UpdateComputeCaseInputSettingsForm,
} from '../../../../api/generated';
import { CaseButtons } from '../CaseButtons/CaseButtons';
Expand All @@ -19,6 +22,9 @@ import { useCaseParameters } from './hooks/useCaseParameters';
import { useGetParameterList } from './hooks/useGetParameterList';
import { useModelArea } from './hooks/useModelArea';
import { useSetSaved } from './hooks/useSetSaved';
import { useMutation } from '@tanstack/react-query';
import { queryClient } from '../../../../auth/queryClient';
import { useParams } from 'react-router-dom';

export const CaseRow = ({
rowCase,
Expand Down Expand Up @@ -62,6 +68,7 @@ export const CaseRow = ({
isOwner: () => boolean;
}) => {
const [caseError, setCaseError] = useState<string>('');
const { modelId } = useParams<{ modelId: string }>();

const indicatorSettings = settingsFilter('Indicator');
const netToGrossSettings = settingsFilter('Net-To-Gross');
Expand Down Expand Up @@ -111,8 +118,31 @@ export const CaseRow = ({
selectedVariogramModels,
);

const cancelJob = useMutation({
mutationFn: JobsService.postApiJobsCancel,
onSuccess: () => {
queryClient.refetchQueries({ queryKey: ['model-cases'] });
},
});

const runCancelJob = async (computeCaseId: string) => {
if (!modelId) return;
const requestBody: PostCancelJobCommand = {
modelId: modelId,
computeCaseId: computeCaseId,
};

const res = await cancelJob.mutateAsync(requestBody);

if (res.success) {
setAlertMessage('Canceled computing case');
}
};

const runRowCase = () => {
if (id) runCase(id);
if (id && rowCase.jobStatus === ComputeJobStatus.RUNNING)
return runCancelJob(id);
if (id) return runCase(id);
};

const handleSaveCase = async (id: string) => {
Expand Down
2 changes: 0 additions & 2 deletions src/pages/Browse/Browse.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ export const Browse = () => {
navigate('/add-model');
}



return (
<>
<Styled.BrowseWrapper>
Expand Down