Skip to content

Commit

Permalink
#6
Browse files Browse the repository at this point in the history
  • Loading branch information
munkhsaikhan committed Sep 5, 2022
1 parent 3911240 commit 337db43
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/plugin-posclient-api/src/graphql/utils/loyalties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { sendLoyaltiesMessage } from '../../messageBroker';
import { IOrderInput } from '../types';

export const checkLoyalties = async (subdomain: string, doc: IOrderInput) => {
if (!doc.customerId) {
return doc;
}

let loyalties: any = {};
try {
loyalties = await sendLoyaltiesMessage({
Expand Down
24 changes: 23 additions & 1 deletion packages/plugin-posclient-api/src/messageBroker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
receiveProductCategory,
receiveUser
} from './graphql/utils/syncUtils';
import { sendRPCMessage } from '@erxes/api-utils/src/messageBroker';

let client;

Expand Down Expand Up @@ -164,7 +165,28 @@ const sendMessageWrapper = async (
): Promise<any> => {
const { SKIP_REDIS } = process.env;
if (SKIP_REDIS) {
const { action } = args;
const { action, isRPC } = args;

// check connected gateway on server and check some plugins isAvailable
if (isRPC) {
const longTask = async () =>
await sendRPCMessage('gateway:isServiceAvailable', serviceName);

const timeout = (cb, interval) => () =>
new Promise(resolve => setTimeout(() => cb(resolve), interval));

const onTimeout = timeout(resolve => resolve(false), 1500);

let response = false;
await Promise.race([longTask, onTimeout].map(f => f())).then(
result => (response = result as boolean)
);

if (!response) {
return args.defaultValue;
}
}

return sendMessage({
client,
serviceDiscovery,
Expand Down

0 comments on commit 337db43

Please sign in to comment.