CheckQueueInProgress
This commit is contained in:
parent
027cbe2814
commit
cd6aa9b1a2
2 changed files with 124 additions and 61 deletions
|
|
@ -28,7 +28,7 @@ import { Profile } from "../entities/Profile";
|
||||||
import { RequestWithUser } from "../middlewares/user";
|
import { RequestWithUser } from "../middlewares/user";
|
||||||
import permission from "../interfaces/permission";
|
import permission from "../interfaces/permission";
|
||||||
import { PermissionOrg } from "../entities/PermissionOrg";
|
import { PermissionOrg } from "../entities/PermissionOrg";
|
||||||
import { setLogDataDiff } from "../interfaces/utils";
|
import { checkQueueInProgress, setLogDataDiff } from "../interfaces/utils";
|
||||||
import { sendToQueueOrg, sendToQueueOrgDraft } from "../services/rabbitmq";
|
import { sendToQueueOrg, sendToQueueOrgDraft } from "../services/rabbitmq";
|
||||||
import { PosMasterAssign } from "../entities/PosMasterAssign";
|
import { PosMasterAssign } from "../entities/PosMasterAssign";
|
||||||
import { PosMasterAct } from "../entities/PosMasterAct";
|
import { PosMasterAct } from "../entities/PosMasterAct";
|
||||||
|
|
@ -142,6 +142,21 @@ export class OrganizationController extends Controller {
|
||||||
@Body() requestBody: CreateOrgRevision,
|
@Body() requestBody: CreateOrgRevision,
|
||||||
@Request() request: RequestWithUser,
|
@Request() request: RequestWithUser,
|
||||||
) {
|
) {
|
||||||
|
try {
|
||||||
|
// CheckQueueInProgress
|
||||||
|
// const [isBusyDraft, isBusyPublish] = await Promise.all([
|
||||||
|
// checkQueueInProgress(`${process.env.AMQ_QUEUE_ORG_DRAFT}`),
|
||||||
|
// checkQueueInProgress(`${process.env.AMQ_QUEUE_ORG}`),
|
||||||
|
// ]);
|
||||||
|
// console.log("✅ ตรวจสอบแล้ว Draft Busy:", isBusyDraft);
|
||||||
|
// console.log("✅ ตรวจสอบแล้ว Publish Busy:", isBusyPublish);
|
||||||
|
// if (isBusyDraft || isBusyPublish) {
|
||||||
|
// console.log("🚫 พบว่ามีงานอยู่ในคิว — error")
|
||||||
|
// throw new HttpError(
|
||||||
|
// HttpStatusCode.CONFLICT,
|
||||||
|
// "ไม่สามารถดำเนินการได้ หากกำลังเผยแพร่หรือสร้างแบบร่างโครงสร้างหน่วยงาน",
|
||||||
|
// );
|
||||||
|
// }
|
||||||
//new main revision
|
//new main revision
|
||||||
const before = null;
|
const before = null;
|
||||||
const revision = Object.assign(new OrgRevision(), requestBody) as OrgRevision;
|
const revision = Object.assign(new OrgRevision(), requestBody) as OrgRevision;
|
||||||
|
|
@ -164,13 +179,15 @@ export class OrganizationController extends Controller {
|
||||||
},
|
},
|
||||||
user: request.user,
|
user: request.user,
|
||||||
};
|
};
|
||||||
try {
|
|
||||||
await sendToQueueOrgDraft(msg);
|
await sendToQueueOrgDraft(msg);
|
||||||
return new HttpSuccess("Draft is being created... Processing in the background.");
|
return new HttpSuccess("Draft is being created... Processing in the background.");
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
|
if (error?.status && error?.message) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
return new HttpError(
|
return new HttpError(
|
||||||
HttpStatusCode.NOT_FOUND,
|
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||||
"Failed to process the draft. Please try again later.",
|
"Failed to process the draft. Please try again later."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -3208,6 +3225,23 @@ export class OrganizationController extends Controller {
|
||||||
*/
|
*/
|
||||||
@Get("get/publish")
|
@Get("get/publish")
|
||||||
async runPublish(@Request() request: RequestWithUser) {
|
async runPublish(@Request() request: RequestWithUser) {
|
||||||
|
try{
|
||||||
|
// CheckQueueInProgress
|
||||||
|
// console.log("🚀 ตรวจสอบว่ามีงานอยู่ในคิว");
|
||||||
|
// const [isBusyDraft, isBusyPublish] = await Promise.all([
|
||||||
|
// checkQueueInProgress(`${process.env.AMQ_QUEUE_ORG_DRAFT}`),
|
||||||
|
// checkQueueInProgress(`${process.env.AMQ_QUEUE_ORG}`),
|
||||||
|
// ]);
|
||||||
|
// console.log("✅ ตรวจสอบแล้ว Draft Busy:", isBusyDraft);
|
||||||
|
// console.log("✅ ตรวจสอบแล้ว Publish Busy:", isBusyPublish);
|
||||||
|
// if (isBusyDraft || isBusyPublish) {
|
||||||
|
// console.log("🚫 พบว่ามีงานอยู่ในคิว — error")
|
||||||
|
// throw new HttpError(
|
||||||
|
// HttpStatusCode.CONFLICT,
|
||||||
|
// "ไม่สามารถดำเนินการได้ หากกำลังเผยแพร่หรือสร้างแบบร่างโครงสร้างหน่วยงาน",
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
|
||||||
const today = new Date();
|
const today = new Date();
|
||||||
today.setHours(0, 0, 0, 0); // Set time to the beginning of the day
|
today.setHours(0, 0, 0, 0); // Set time to the beginning of the day
|
||||||
const orgRevisionPublish = await this.orgRevisionRepository
|
const orgRevisionPublish = await this.orgRevisionRepository
|
||||||
|
|
@ -3247,6 +3281,15 @@ export class OrganizationController extends Controller {
|
||||||
};
|
};
|
||||||
sendToQueueOrg(msg);
|
sendToQueueOrg(msg);
|
||||||
return new HttpSuccess();
|
return new HttpSuccess();
|
||||||
|
} catch (error: any) {
|
||||||
|
if (error?.status && error?.message) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
return new HttpError(
|
||||||
|
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||||
|
"Failed to process the publish. Please try again later."
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -503,6 +503,26 @@ export function editLogSequence(req: RequestWithUser, index: number, data: LogSe
|
||||||
req.app.locals.logData.sequence[index] = data;
|
req.app.locals.logData.sequence[index] = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function checkQueueInProgress(queueName: string) {
|
||||||
|
// const axios = require('axios');
|
||||||
|
// console.log("Checking queue in progress");
|
||||||
|
// const res = await axios.get(`${process.env.RABBIT_API_URL}/api/queues/%2F/${queueName}`, {
|
||||||
|
// auth: { username: process.env.RABBIT_USER , password: process.env.RABBIT_PASS },
|
||||||
|
// });
|
||||||
|
|
||||||
|
// const q = res.data;
|
||||||
|
|
||||||
|
// console.log(`Queue "${queueName}" has:`);
|
||||||
|
// console.log(` - ${q.messages_ready} messages ready`);
|
||||||
|
// console.log(` - ${q.messages_unacknowledged} messages in progress (unacked)`);
|
||||||
|
|
||||||
|
// if (q.messages_unacknowledged > 0) {
|
||||||
|
// return true;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return false;
|
||||||
|
}
|
||||||
|
|
||||||
export function commandTypePath(commandCode: string): string | null {
|
export function commandTypePath(commandCode: string): string | null {
|
||||||
switch (commandCode) {
|
switch (commandCode) {
|
||||||
case "C-PM-01":
|
case "C-PM-01":
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue