Skip to content

Commit

Permalink
Merge pull request #175 from ymaheshwari1/fix/schedule-job
Browse files Browse the repository at this point in the history
Fixed: issue when scheduling/reordering jobs from schedule page
  • Loading branch information
adityasharma7 authored Feb 20, 2023
2 parents c80a302 + 4d86697 commit 25992d3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
8 changes: 6 additions & 2 deletions src/components/JobReorderModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</ion-reorder-group>

<ion-fab vertical="bottom" horizontal="end" slot="fixed">
<ion-fab-button @click="save()" :disabled="failedJobs.length">
<ion-fab-button @click="save()" :disabled="failedJobs.length || isReordering">
<ion-icon :icon="saveOutline" />
</ion-fab-button>
</ion-fab>
Expand Down Expand Up @@ -77,7 +77,8 @@ export default defineComponent({
return {
failedJobs: [] as any,
successJobs: [] as any,
modifiedJobs: JSON.parse(JSON.stringify((this as any).jobs))
modifiedJobs: JSON.parse(JSON.stringify((this as any).jobs)),
isReordering: false
}
},
computed: {
Expand Down Expand Up @@ -120,6 +121,7 @@ export default defineComponent({
this.modifiedJobs = updatedSeq
},
async save() {
this.isReordering = true;
this.failedJobs = []
this.successJobs = []
Expand Down Expand Up @@ -155,6 +157,8 @@ export default defineComponent({
logger.error(err)
}
}))
this.isReordering = false;
// If there are no failed jobs then redirecting the user to the threshold updates page
if (!this.failedJobs.length) {
this.closeModal(true);
Expand Down
32 changes: 25 additions & 7 deletions src/views/ScheduleThreshold.vue
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,12 @@ export default defineComponent({
const jobRunTime = this.updatedJobsOrder.find((job: any) => !job.jobId)?.runTime
let diffSeq = this.findJobDiff(this.initialJobsOrder, this.jobsForReorder)
this.updatedJobsOrder = Object.keys(diffSeq).map((key) => diffSeq[key])
// filtered jobs by removing the new job as we need to update already existing job
const jobsToUpdate = this.updatedJobsOrder.filter((job: any) => job.jobId)
// re-initialized params object from query as there is no need for grouping or pagination when storing the query
solrQuery.json.params = {
"q.op": "AND"
Expand All @@ -295,8 +301,6 @@ export default defineComponent({
// checking whether the service has been scheduled successfully, if yes then only updating other jobs otherwise not
if (this.successJobs.includes('')) {
// filtered jobs by removing the new job as we need to update already existing job
const jobsToUpdate = this.updatedJobsOrder.filter((job: any) => job.jobId)
await Promise.allSettled(jobsToUpdate.map(async (job: any) => {
// using resp and checking it, as we need jobId that will not be available in case
Expand All @@ -306,7 +310,6 @@ export default defineComponent({
const payload = {
'jobId': job.jobId,
'systemJobEnumId': job.systemJobEnumId,
'recurrenceTimeZone': this.userProfile.userTimeZone,
'tempExprId': job.frequency ? job.frequency : job.jobStatus,
'statusId': "SERVICE_PENDING"
} as any
Expand All @@ -333,18 +336,20 @@ export default defineComponent({
}))
} else {
logger.error('Failed to schedule service, hence other jobs are not updated')
this.failedJobs = this.jobsForReorder.map((job: any) => job.jobId)
this.failedJobs = this.updatedJobsOrder.map((job: any) => job.jobId)
showToast(translate('Failed to schedule service, hence other jobs are not updated'))
}
} else {
showToast(translate('Failed to schedule service, hence other jobs are not updated'))
logger.error('Failed to schedule service as search preference is not created, hence other jobs are not updated')
this.failedJobs = this.jobsForReorder.map((job: any) => job.jobId)
this.failedJobs = this.updatedJobsOrder.map((job: any) => job.jobId)
this.failedJobs.push('')
}
} catch (err) {
logger.error(err)
showToast(translate('Something went wrong'))
this.failedJobs = this.jobsForReorder.map((job: any) => job.jobId)
this.failedJobs = this.updatedJobsOrder.map((job: any) => job.jobId)
this.failedJobs.push('')
}
this.isServiceScheduling = false
emitter.emit('dismissLoader');
Expand Down Expand Up @@ -541,7 +546,7 @@ export default defineComponent({
emitter.emit('dismissLoader');
}
},
async mounted() {
async ionViewWillEnter() {
await this.fetchExportThresholdJobs();
// Finding the runTime of the first job or if there are no pending jobs then assigning current time
Expand All @@ -567,6 +572,19 @@ export default defineComponent({
this.initialJobsOrder = JSON.parse(JSON.stringify(this.jobsForReorder))
this.updatedJobsOrder = [ newJob ]
},
ionViewDidLeave() {
// TODO: remove this initialization from the hook and update the code accordingly
// Done this as currently the component is not being unmounted when changing the route as there exist
// a connection between parent and child and ionViewWillEnter hook does not reinitialize the
// local data property
this.jobName = ''
this.jobsForReorder = []
this.initialJobsOrder = []
this.initialRunTime = ''
this.updatedJobsOrder = []
this.failedJobs = []
this.successJobs = []
},
setup() {
const store = useStore();
const router = useRouter();
Expand Down

0 comments on commit 25992d3

Please sign in to comment.