Skip to content

Commit

Permalink
Merge pull request #1883 from Inist-CNRS/fix/precomputed-cancel
Browse files Browse the repository at this point in the history
Fix precomputed job cancelation
  • Loading branch information
adguernier authored Feb 2, 2024
2 parents 16b9892 + f7a6ee2 commit 82b79b6
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 27 deletions.
11 changes: 3 additions & 8 deletions src/api/controller/api/precomputed.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
getPrecomputedDataPreview,
setPrecomputedJobId,
} from '../../services/precomputed/precomputed';
import { cancelJob, getActiveJob } from '../../workers/tools';
import { cancelJob } from '../../workers/tools';
import getLocale from '../../../common/getLocale';

export const setup = async (ctx, next) => {
Expand Down Expand Up @@ -65,13 +65,8 @@ export const putPrecomputed = async (ctx, id) => {

export const deletePrecomputed = async (ctx, id) => {
try {
const activeJob = await getActiveJob(ctx.tenant);
if (
activeJob?.data?.jobType === PRECOMPUTER &&
activeJob?.data?.id === id
) {
cancelJob(ctx, PRECOMPUTER);
}
const precomputed = await ctx.precomputed.findOneById(id);
await cancelJob(ctx, PRECOMPUTER, precomputed?.name);
await ctx.precomputed.delete(id);
ctx.status = 200;
ctx.body = { message: 'ok' };
Expand Down
1 change: 1 addition & 0 deletions src/api/controller/api/precomputed.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ describe('Precomputed controller', () => {
delete: async () => {
throw new Error('ERROR!');
},
findOneById: async () => ({ name: 'NAME' }),
},
};

Expand Down
7 changes: 6 additions & 1 deletion src/api/models/precomputed.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ export default async db => {
};

collection.delete = async id => {
await db.collection(`pc_${id}`).drop();
try {
await db.collection(`pc_${id}`).drop();
} catch {
// Collection does not exist, no big deal
console.warn(`Failed to drop collection 'pc_${id}'`);
}
return collection.remove({
$or: [{ _id: new ObjectId(id) }, { _id: id }],
});
Expand Down
11 changes: 7 additions & 4 deletions src/api/services/precomputed/precomputed.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,13 @@ export const getComputedFromWebservice = async ctx => {
const tenant = ctx.tenant;
const { id: precomputedId, callId, askForPrecomputedJobId } = ctx.job.data;

const {
webServiceUrl,
name: precomputedName,
} = await ctx.precomputed.findOneById(precomputedId);
const precomputed = await ctx.precomputed.findOneById(precomputedId);
if (!precomputed) {
// Entry may have been deleted before the webservice called us back.
// We can ignore the reply in that case.
return;
}
const { webServiceUrl, name: precomputedName } = precomputed;
const webServiceBaseURL = new RegExp('.*\\/').exec(webServiceUrl)[0];
progress.initialize(tenant);
progress.start(ctx.tenant, {
Expand Down
1 change: 1 addition & 0 deletions src/app/custom/translations.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"clear_model" "Clear model" "Effacer le modèle"
"sign_out" "Sign out" "Déconnexion"
"back_to_list" "Back to list" "Retourner à la liste"
"back" "Back" "Retour"
"not_found" "Resource not found" "Ressource non trouvée"
"powered" "Powered by" "Propulsé par"
"loading_resource" "Resource loading..." "Ressource en cours de chargement..."
Expand Down
23 changes: 12 additions & 11 deletions src/app/js/admin/Appbar/JobProgress.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,17 +258,18 @@ const JobProgressComponent = props => {
</Typography>
)}
</Box>
{progress?.status !== UPLOADING_DATASET && (
<Button
sx={styles.cancelButton}
color="inherit"
onClick={() => {
setIsCancelDialogOpen(true);
}}
>
<Cancel />
</Button>
)}
{progress?.status !== UPLOADING_DATASET &&
progress?.type !== 'precomputer' && (
<Button
sx={styles.cancelButton}
color="inherit"
onClick={() => {
setIsCancelDialogOpen(true);
}}
>
<Cancel />
</Button>
)}
</Box>
{!!progress?.progress && !!progress?.target && (
<LinearProgress
Expand Down
6 changes: 3 additions & 3 deletions src/app/js/admin/precomputed/PrecomputedForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ export const PrecomputedForm = ({
setIsLoading(false);
};

const handleCancel = () => {
const handleBack = () => {
history.push('/data/precomputed');
};

Expand Down Expand Up @@ -594,9 +594,9 @@ export const PrecomputedForm = ({
<Box>
<CancelButton
sx={{ height: '100%' }}
onClick={handleCancel}
onClick={handleBack}
>
{polyglot.t('cancel')}
{polyglot.t('back')}
</CancelButton>
<Button
variant="contained"
Expand Down

0 comments on commit 82b79b6

Please sign in to comment.