From a45f97e268dfd0a88036a1671c37486846076f76 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Mon, 18 Nov 2024 11:01:44 +0700 Subject: [PATCH 1/4] =?UTF-8?q?=E0=B8=97=E0=B8=94=E0=B8=A5=E0=B8=AD?= =?UTF-8?q?=E0=B8=87=E0=B8=9B=E0=B8=B4=E0=B8=94=20channel.prefetch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/services/rabbitmq.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/rabbitmq.ts b/src/services/rabbitmq.ts index d7cc555a..9919eeb8 100644 --- a/src/services/rabbitmq.ts +++ b/src/services/rabbitmq.ts @@ -27,7 +27,7 @@ export async function init() { channel.assertQueue(queue, { durable: true }); //----> (1.5) assert queue and set durable (if "true" save to disk on RabbitMQ) channel.assertQueue(queue_org, { durable: true }); - channel.prefetch(1); + // channel.prefetch(1); sendToQueue = (payload: any, persistent = true) => { //----> (2) sendQueue To RabbitMQ and set persistent (if "true" redo the failed queue when server run again) From 0c70fe006f601de24a2eb035006adbc98adbed95 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Mon, 18 Nov 2024 11:25:50 +0700 Subject: [PATCH 2/4] test --- src/services/rabbitmq.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/services/rabbitmq.ts b/src/services/rabbitmq.ts index 9919eeb8..1ccebf45 100644 --- a/src/services/rabbitmq.ts +++ b/src/services/rabbitmq.ts @@ -27,7 +27,7 @@ export async function init() { channel.assertQueue(queue, { durable: true }); //----> (1.5) assert queue and set durable (if "true" save to disk on RabbitMQ) channel.assertQueue(queue_org, { durable: true }); - // channel.prefetch(1); + channel.prefetch(1); sendToQueue = (payload: any, persistent = true) => { //----> (2) sendQueue To RabbitMQ and set persistent (if "true" redo the failed queue when server run again) @@ -42,8 +42,8 @@ export async function init() { console.log("[AMQ] Listening for message..."); - createConsumer(queue, channel, handler); //----> (3) Process Consumer - createConsumer(queue_org, channel, handler_org); + await createConsumer(queue, channel, handler); //----> (3) Process Consumer + await createConsumer(queue_org, channel, handler_org); // createConsumer(queue2, channel, handler2); } From 645b73e2e6edd0a015254dd11c47aa06d9854b6c Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Mon, 18 Nov 2024 12:02:45 +0700 Subject: [PATCH 3/4] checkpoint --- src/services/rabbitmq.ts | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/src/services/rabbitmq.ts b/src/services/rabbitmq.ts index 1ccebf45..771d73d7 100644 --- a/src/services/rabbitmq.ts +++ b/src/services/rabbitmq.ts @@ -19,11 +19,11 @@ export async function init() { const connection = await amqp.connect(url); //----> (1.3) set up url with amqp protocol - console.log(connection ? "[AMQ] connection success" : "[AMQ] connection failed"); + console.log(connection ? "[AMQ] Connection success" : "[AMQ] Connection failed"); const channel = await connection.createChannel(); //----> (1.4) create Channel - console.log(channel ? "[AMQ] create channel success" : "[AMQ] create channel failed"); + console.log(channel ? "[AMQ] Create channel success" : "[AMQ] Create channel failed"); channel.assertQueue(queue, { durable: true }); //----> (1.5) assert queue and set durable (if "true" save to disk on RabbitMQ) channel.assertQueue(queue_org, { durable: true }); @@ -58,14 +58,12 @@ function createConsumer( //----> consumer queue, async (msg) => { if (!msg) return; - console.log("[AMQ] on on create consumer"); - if ((await handler(msg)) || retries++ >= 3) { retries = 0; - console.log("[AMQ] process consumer success"); + console.log("[AMQ] Process consumer success"); return channel.ack(msg); } - console.log("[AMQ] process consumer fail"); + console.log("[AMQ] Process consumer fail"); return await new Promise((resolve) => setTimeout(() => resolve(channel.nack(msg)), 3000)); }, { noAck: false }, @@ -73,31 +71,18 @@ function createConsumer( //----> consumer } async function handler(msg: amqp.ConsumeMessage): Promise { - console.log(msg ? "[AMQ] on handler" : "[AMQ] don't handler"); + console.log(msg ? "[AMQ] On handler" : "[AMQ] Not handler"); //----> condition before process consumer const repo = AppDataSource.getRepository(Command); const { data, token, user } = JSON.parse(msg.content.toString()); - - console.log(repo ? "[AMQ] have repo" : "[AMQ] don't have repo"); - const { id, status, lastUpdateUserId, lastUpdateFullName, lastUpdatedAt } = data; - - console.log(data ? "[AMQ] have data" : "[AMQ] don't have data"); - const command = await repo.findOne({ where: { id: id }, relations: ["commandType", "commandRecives"], }); - - console.log(command ? "[AMQ] have command" : "[AMQ] don't have command"); - if (!command) return true; - const path = commandTypePath(command.commandType.code); if (path == null) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบประเภทคำสั่งนี้ในระบบ"); - - console.log(path ? "[AMQ] have path" : "[AMQ] don't have path"); - return await new CallAPI() .PostData( { From 8f2b8568ef806721a7d30b12a7a93cc9967d705e Mon Sep 17 00:00:00 2001 From: Bright Date: Mon, 18 Nov 2024 13:38:41 +0700 Subject: [PATCH 4/4] add salary --- src/controllers/ProfileController.ts | 1 + src/controllers/ProfileEmployeeTempController.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 0ac4d955..5d5d9faf 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -5782,6 +5782,7 @@ export class ProfileController extends Controller { child4ShortName: child4 == null ? null : child4.orgChild4ShortName, node: null, nodeId: null, + salary: profile.amount, education: profile && profile.profileEducations.length > 0 ? `${profile.profileEducations[0].degree ?? ""}/${profile.profileEducations[0].field ?? ""}` diff --git a/src/controllers/ProfileEmployeeTempController.ts b/src/controllers/ProfileEmployeeTempController.ts index f1e4f66b..ab3ff5bb 100644 --- a/src/controllers/ProfileEmployeeTempController.ts +++ b/src/controllers/ProfileEmployeeTempController.ts @@ -3758,6 +3758,7 @@ export class ProfileEmployeeTempController extends Controller { node: null, nodeId: null, posNo: shortName, + salary: profile.amount, education: profile && profile.profileEducations.length > 0 ? `${profile.profileEducations[0].degree ?? ""}/${profile.profileEducations[0].field ?? ""}`