Skip to content

Commit

Permalink
Implemented: support to run a group from the list page(hotwax#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
ymaheshwari1 committed Aug 12, 2024
1 parent b7249fb commit c23c292
Showing 1 changed file with 72 additions and 3 deletions.
75 changes: 72 additions & 3 deletions src/components/GroupActionsPopover.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<ion-content>
<ion-list>
<ion-list-header>{{ group.groupName }}</ion-list-header>
<ion-item button>
<ion-item button @click="runNow">
<ion-icon slot="start" :icon="flashOutline" />
{{ translate("Run now") }}
</ion-item>
Expand All @@ -20,6 +20,7 @@

<script setup lang="ts">
import {
alertController,
IonContent,
IonIcon,
IonItem,
Expand All @@ -29,13 +30,16 @@ import {
} from "@ionic/vue";
import { flashOutline, pauseOutline, playOutline } from 'ionicons/icons'
import { translate } from "@/i18n"
import { defineProps } from "vue"
import { computed, defineProps } from "vue"
import { OrderRoutingService } from "@/services/RoutingService";
import { hasError, showToast } from "@/utils";
import logger from "@/logger";
import store from "@/store";
import { useStore } from "vuex";
const store = useStore()
const props = defineProps(["group"])
const isOmsConnectionExist = computed(() => store.getters["util/isOmsConnectionExist"])
async function updateGroupStatus(paused: string) {
let routingGroups = [];
Expand All @@ -59,4 +63,69 @@ async function updateGroupStatus(paused: string) {
popoverController.dismiss({ routingGroups });
}
async function runNow() {
// If this is the first time then we are fetching the omsConnection status, as if the value of isOmsConnectionExist value is a boolean it means we have previously fetched the connection status
if(typeof isOmsConnectionExist.value !== "boolean") {
await store.dispatch("util/checkOmsConnectionStatus")
}
if(!isOmsConnectionExist.value) {
return;
}
const scheduleAlert = await alertController
.create({
header: translate("Run now"),
message: translate("Running this schedule now will not replace this schedule. A copy of this schedule will be created and run immediately. You may not be able to reverse this action."),
buttons: [
{
text: translate("Cancel"),
role: "cancel",
},
{
text: translate("Run now"),
handler: async () => {
popoverController.dismiss()
const job = props.group?.schedule || {}
// Checking that if we already have the job schedule before calling runNow, because if the job scheduler is not present then runNow action can't be performed
// If the scheduler for the job is available then we will have jobName, if not then first scheduling the job in draft status just to create a routing schedule and then calling runNow action
if(!job.jobName) {
const payload = {
routingGroupId: props.group.routingGroupId,
paused: "Y", // passing Y as we just need to configure the scheduler and do not need to schedule it in active state
}
try {
const resp = await OrderRoutingService.scheduleBrokering(payload)
if(hasError(resp)) {
throw resp.data
}
// Updating jobName as if the user again clicks the runNow button then in that we don't want to call the scheduleBrokering service
job.jobName = resp.data.jobName
} catch(err) {
logger.error(err)
return;
}
}
try {
const resp = await OrderRoutingService.runNow(props.group.routingGroupId)
if(!hasError(resp) && resp.data.jobRunId) {
showToast(translate("Service has been scheduled"))
} else {
throw resp.data
}
} catch(err) {
showToast(translate("Failed to schedule service"))
logger.error(err)
}
}
}
]
});
return scheduleAlert.present();
}
</script>

0 comments on commit c23c292

Please sign in to comment.