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

Fixed: Duplicate batch jobs visible when scheduling a new batch job (#393) #403

Merged
merged 2 commits into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 1 addition & 2 deletions src/components/BatchModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,10 @@ export default defineComponent({
}
if (job?.status === 'SERVICE_DRAFT') {
await this.store.dispatch('job/scheduleService', job)
this.closeModal()
} else if (job?.status === 'SERVICE_PENDING') {
await this.store.dispatch('job/updateJob', job)
this.closeModal()
}
this.closeModal()
},
updateRunTime(ev: CustomEvent) {
this.jobRunTime = handleDateTimeInput(ev['detail'].value)
Expand Down
64 changes: 28 additions & 36 deletions src/store/modules/job/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ const actions: ActionTree<JobState, RootState> = {
status: job.statusId
}
return cached;
}, cached)
}, cached)

responseJobs.filter((job: any) => job.statusId === 'SERVICE_DRAFT').map((job: any) => {
delete job.runTime;
Expand Down Expand Up @@ -529,18 +529,21 @@ const actions: ActionTree<JobState, RootState> = {
resp = await JobService.scheduleJob({ ...job.runtimeData, ...payload });
if (resp.status == 200 && !hasError(resp)) {
showToast(translate('Service has been scheduled'));
const jobs = await dispatch('fetchJobs', {
const fetchJobsResponses = await dispatch('fetchJobs', {
inputFields: {
'systemJobEnumId': payload.systemJobEnumId,
'systemJobEnumId_op': 'equals',
'statusId': "SERVICE_PENDING",
'statusId_op': 'equals'
},
orderBy: "runTime ASC"
})
const fetchJobsResponse = jobs[0];
if(fetchJobsResponse.status === 200 && !hasError(fetchJobsResponse) && fetchJobsResponse.data?.docs?.length) {
commit(types.JOB_CURRENT_UPDATED, fetchJobsResponse.data?.docs[0]);
// TODO
adityasharma7 marked this conversation as resolved.
Show resolved Hide resolved
const fetchJobsResponse = fetchJobsResponses.find((fetchJobsResponse: any) => {
return !hasError(fetchJobsResponse) &&
fetchJobsResponse.data?.docs?.length &&
fetchJobsResponse.data?.docs[0].statusId == "SERVICE_PENDING";
});
if(fetchJobsResponse) {
commit(types.JOB_CURRENT_UPDATED, fetchJobsResponse.data.docs[0]);
return job;
}
} else {
Expand Down Expand Up @@ -586,23 +589,24 @@ const actions: ActionTree<JobState, RootState> = {
} as any

const resp = await JobService.updateJob(payload)
// Fetch and update current only when there is object in current
// Skip job can be performed from pipeline page too causing side effects
if (state.current && Object.keys(state.current).length) {
let jobs = await dispatch('fetchJobs', {
const fetchJobsResponses = await dispatch('fetchJobs', {
inputFields: {
'systemJobEnumId': payload.systemJobEnumId,
'systemJobEnumId_op': 'equals'
}
})
if (jobs.status === 200 && !hasError(jobs) && jobs.data?.docs?.length) {
jobs = jobs.data?.docs;
// Fetch and update current only when there is object in current
// Skip job can be performed from pipeline page too causing side effects
if (state.current && Object.keys(state.current).length) {
const fetchJobsResponse = fetchJobsResponses.find((fetchJobsResponse: any) => {
return !hasError(fetchJobsResponse) &&
fetchJobsResponse.data?.docs?.length &&
fetchJobsResponse.data?.docs[0].statusId == "SERVICE_PENDING";
});
const jobs = fetchJobsResponse.data?.docs;
const currentJob = jobs.find((currentJob: any) => currentJob?.jobId === job?.jobId);
commit(types.JOB_CURRENT_UPDATED, currentJob);
}
}
// This is done for batch jobs
commit(types.JOB_UPDATED, { job });

return resp;
},
Expand Down Expand Up @@ -671,32 +675,20 @@ const actions: ActionTree<JobState, RootState> = {
jobId: job.jobId
});
if (resp.status == 200 && !hasError(resp)) {
// TODO: When we are trying to cancel the job from pipeline page those jobs are not in the cached state, so we need to
// handle this case because we were getting error :- "can not set status and statusId for pending jobs in cached state".
const cachedJob = state.cached[job?.systemJobEnumId]
if(cachedJob) {
cachedJob.statusId = 'SERVICE_DRAFT'
cachedJob.status = 'SERVICE_DRAFT'
// deleting the enum from cached job as we will not store the job with cancelled status
// TODO: remove the code to change the status to SERVICE_DRAFT after verifying the flow
delete state.cached[job?.systemJobEnumId]

commit(types.JOB_UPDATED, { cachedJob });
}

// Fetch and update current only when there is object in current
// Cancel job can be performed from pipeline page too causing side effects
if (state.current && Object.keys(state.current).length) {
const jobs = await dispatch('fetchJobs', {
const fetchJobsResponses = await dispatch('fetchJobs', {
inputFields: {
'systemJobEnumId': job.systemJobEnumId,
'systemJobEnumId_op': 'equals'
}
})
const fetchJobsResponse = jobs[0];
if (fetchJobsResponse.status === 200 && !hasError(fetchJobsResponse) && fetchJobsResponse.data?.docs.length) {
commit(types.JOB_CURRENT_UPDATED, fetchJobsResponse);
}
// Fetch and update current only when there is object in current
// Cancel job can be performed from pipeline page too causing side effects
if (state.current && Object.keys(state.current).length) {
const fetchJobsResponse = fetchJobsResponses[0];
if (fetchJobsResponse.status === 200 && !hasError(fetchJobsResponse) && fetchJobsResponse.data?.docs.length) {
commit(types.JOB_CURRENT_UPDATED, fetchJobsResponse);
}
}
showToast(translate('Service updated successfully'))
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/store/modules/job/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const getters: GetterTree <JobState, RootState> = {
return state.temporalExp[id];
},
getJob: (state) => (id: string): any => {
return state.cached[id]
return state.cached[id];
},
getEnumDescription: (state) => (id: string): any => {
return state.enumIds[id]?.description;
Expand Down
1 change: 0 additions & 1 deletion src/store/modules/job/mutation-types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export const SN_JOB = 'job'
export const JOB_UPDATED_BULK = SN_JOB + '/UPDATED_BULK'
export const JOB_UPDATED = SN_JOB + '/UPDATED'
export const JOB_PENDING_UPDATED = SN_JOB + '/PENDING_UPDATED'
export const JOB_TEMPORAL_EXPRESSION_UPDATED = SN_JOB + '/TEMPORAL_EXPRESSION_UPDATED'
export const JOB_DESCRIPTION_UPDATED = SN_JOB + '/DESCRIPTION_UPDATED'
Expand Down
6 changes: 0 additions & 6 deletions src/store/modules/job/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ const mutations: MutationTree <JobState> = {
[types.JOB_UPDATED_BULK] (state, payload) {
state.cached = payload
},
[types.JOB_UPDATED] (state, payload) {
state.cached[payload.systemJobEnumId] = {
...state.cached[payload.systemJobEnumId],
payload
}
},
[types.JOB_PENDING_UPDATED] (state, payload) {
state.pending.list = payload.jobs;
state.pending.total = payload.total;
Expand Down