Skip to content

Commit

Permalink
reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
furknyavuz committed Apr 6, 2022
1 parent ed431d7 commit 430116a
Show file tree
Hide file tree
Showing 13 changed files with 811 additions and 832 deletions.
55 changes: 26 additions & 29 deletions app/consumer/auth-queue.consumer.ts
Original file line number Diff line number Diff line change
@@ -1,69 +1,66 @@
import {
AuthActionType,
ContextArgs,
QueueConsumer,
} from '@open-template-hub/common';
import { AuthActionType, ContextArgs, QueueConsumer, } from '@open-template-hub/common';

export class AuthQueueConsumer implements QueueConsumer {
private channel: any;
private ctxArgs: ContextArgs = {} as ContextArgs;

constructor() {}
constructor() {
}

init = (channel: string, ctxArgs: ContextArgs) => {
init = ( channel: string, ctxArgs: ContextArgs ) => {
this.channel = channel;
this.ctxArgs = ctxArgs;
return this;
};

onMessage = async (msg: any) => {
if (msg !== null) {
onMessage = async ( msg: any ) => {
if ( msg !== null ) {
const msgStr = msg.content.toString();
const msgObj = JSON.parse(msgStr);
const msgObj = JSON.parse( msgStr );

const message: AuthActionType = msgObj.message;

// Decide requeue in the error handling
let requeue = false;

if (message.example) {
if ( message.example ) {
var exampleHook = async () => {
console.log('Auth server example');
console.log( 'Auth server example' );
};

await this.operate(msg, msgObj, requeue, exampleHook);
await this.operate( msg, msgObj, requeue, exampleHook );
} else {
console.log('Message will be rejected: ', msgObj);
this.channel.reject(msg, false);
console.log( 'Message will be rejected: ', msgObj );
this.channel.reject( msg, false );
}
}
};

private operate = async (
msg: any,
msgObj: any,
requeue: boolean,
hook: Function
msg: any,
msgObj: any,
requeue: boolean,
hook: Function
) => {
try {
console.log(
'Message Received with deliveryTag: ' + msg.fields.deliveryTag,
msgObj
'Message Received with deliveryTag: ' + msg.fields.deliveryTag,
msgObj
);
await hook();
await this.channel.ack(msg);
await this.channel.ack( msg );
console.log(
'Message Processed with deliveryTag: ' + msg.fields.deliveryTag,
msgObj
'Message Processed with deliveryTag: ' + msg.fields.deliveryTag,
msgObj
);
} catch (e) {
} catch ( e ) {
console.log(
'Error with processing deliveryTag: ' + msg.fields.deliveryTag,
msgObj,
e
'Error with processing deliveryTag: ' + msg.fields.deliveryTag,
msgObj,
e
);

this.channel.nack(msg, false, requeue);
this.channel.nack( msg, false, requeue );
}
};
}
Loading

0 comments on commit 430116a

Please sign in to comment.