Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
kjamrog committed Dec 11, 2024
1 parent 6630176 commit 6d51f47
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 25 deletions.
11 changes: 8 additions & 3 deletions packages/core/lib/queues/AbstractQueueService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,15 @@ export abstract class AbstractQueueService<
messageId?: string,
) {
const messageTimestamp = message ? this.tryToExtractTimestamp(message) : undefined
const messageProcessingMilliseconds = messageTimestamp ? Date.now() - messageTimestamp.getTime() : undefined
const messageProcessingMilliseconds = messageTimestamp
? Date.now() - messageTimestamp.getTime()
: undefined

// @ts-ignore
const messageType = (message && this.messageTypeField in message) ? message[this.messageTypeField] : undefined
const messageType =
message && this.messageTypeField in message
? // @ts-ignore
message[this.messageTypeField]
: undefined

this.logger.debug(
{
Expand Down
13 changes: 4 additions & 9 deletions packages/sqs/lib/sqs/AbstractSqsConsumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,9 @@ export abstract class AbstractSqsConsumer<

const visibilityTimeout = await this.getQueueVisibilityTimeout()

try {
this.consumers = Array.from({ length: this.concurrentConsumersAmount })
.map((_) => this.createConsumer({ visibilityTimeout }))
} catch (err) {
console.log(err)
console.log(this.consumers)
}

this.consumers = Array.from({ length: this.concurrentConsumersAmount }).map((_) =>
this.createConsumer({ visibilityTimeout }),
)

for (const consumer of this.consumers) {
consumer.on('error', (err) => {
Expand Down Expand Up @@ -283,7 +278,7 @@ export abstract class AbstractSqsConsumer<
private stopExistingConsumers(abort?: boolean) {
for (const consumer of this.consumers) {
consumer.stop({
abort
abort,
})
}
}
Expand Down
28 changes: 16 additions & 12 deletions packages/sqs/test/consumers/SqsPermissionConsumer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { SINGLETON_CONFIG, registerDependencies } from '../utils/testContext'
import type { Dependencies } from '../utils/testContext'

import { SqsPermissionConsumer } from './SqsPermissionConsumer'
import type { PERMISSIONS_ADD_MESSAGE_TYPE } from "./userConsumerSchemas";
import type { PERMISSIONS_ADD_MESSAGE_TYPE } from './userConsumerSchemas'

describe('SqsPermissionConsumer', () => {
describe('init', () => {
Expand Down Expand Up @@ -606,7 +606,7 @@ describe('SqsPermissionConsumer', () => {

beforeEach(async () => {
diContainer = await registerDependencies({
permissionConsumer: asFunction(dependencies => {
permissionConsumer: asFunction((dependencies) => {
return new SqsPermissionConsumer(dependencies, {
creationConfig: {
queue: {
Expand All @@ -616,7 +616,7 @@ describe('SqsPermissionConsumer', () => {
concurrentConsumersAmount: 10,
logMessages: true,
})
})
}),
})
sqsClient = diContainer.cradle.sqsClient
publisher = diContainer.cradle.permissionPublisher
Expand All @@ -638,16 +638,20 @@ describe('SqsPermissionConsumer', () => {

it('process all messages properly', async () => {
const messagesAmount = 100
const messages: PERMISSIONS_ADD_MESSAGE_TYPE[] = Array.from({ length: messagesAmount }).map((_, i) => ({
id: `${i}`,
messageType: 'add',
timestamp: new Date().toISOString(),
}))
const messages: PERMISSIONS_ADD_MESSAGE_TYPE[] = Array.from({ length: messagesAmount }).map(
(_, i) => ({
id: `${i}`,
messageType: 'add',
timestamp: new Date().toISOString(),
}),
)

await Promise.all(messages.map(async (m) => {
await publisher.publish(m)
await consumer.handlerSpy.waitForMessageWithId(m.id, 'consumed')
}))
await Promise.all(
messages.map(async (m) => {
await publisher.publish(m)
await consumer.handlerSpy.waitForMessageWithId(m.id, 'consumed')
}),
)

// Verifies that each message is executed only once
expect(consumer.addCounter).toBe(messagesAmount)
Expand Down
2 changes: 1 addition & 1 deletion packages/sqs/test/consumers/SqsPermissionConsumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class SqsPermissionConsumer extends AbstractSqsConsumer<
}
this.addCounter += context.incrementAmount
this.processedMessagesIds.add(_message.id)
return Promise.resolve({result: 'success'})
return Promise.resolve({ result: 'success' })
},
{
preHandlerBarrier: options.addPreHandlerBarrier,
Expand Down

0 comments on commit 6d51f47

Please sign in to comment.