franchising 0.6.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -72
- package/dist/{accounts-TyMPSHM0.cjs → accounts-BscmRiXc.cjs} +26 -1
- package/dist/{accounts-TyMPSHM0.cjs.map → accounts-BscmRiXc.cjs.map} +1 -1
- package/dist/{accounts-B4bnTXUd.js → accounts-DJRg4gXj.js} +26 -1
- package/dist/{accounts-B4bnTXUd.js.map → accounts-DJRg4gXj.js.map} +1 -1
- package/dist/cli/template-assets/api/src/main.ts +13 -11
- package/dist/cli/template-assets/api/src/modules/health/controller.ts +25 -4
- package/dist/cli/template-assets/api/src/shared/http/errors.ts +17 -0
- package/dist/cli/template-assets/cloudflare/cache.service.ts +1 -0
- package/dist/cli/template-assets/cloudflare/queue.service.ts +1 -0
- package/dist/cli/template-assets/cloudflare/worker.ts +4 -0
- package/dist/cli/template-assets/github/PULL_REQUEST_TEMPLATE.md +37 -0
- package/dist/cli/template-assets/observability/adapters.ts +37 -0
- package/dist/cli/template-assets/observability/bootstrap.ts +48 -0
- package/dist/cli/template-assets/observability/env.ts +21 -0
- package/dist/cli/template-assets/observability/index.ts +10 -0
- package/dist/cli/template-assets/observability/lifecycle.ts +97 -0
- package/dist/cli/template-assets/observability/local-index.ts +9 -0
- package/dist/cli/template-assets/observability/register.ts +12 -0
- package/dist/cli/template-assets/packages/jobs/src/index.ts +4 -40
- package/dist/cli/template-assets/packages/jobs/src/shared/queue/job-id.ts +9 -0
- package/dist/cli/template-assets/packages/jobs/src/shared/queue/options.ts +7 -0
- package/dist/cli/template-assets/packages/jobs/src/shared/queue/prefix.ts +18 -0
- package/dist/cli/template-assets/packages/queue/src/index.ts +4 -0
- package/dist/cli/template-assets/packages/queue/src/shared/errors/failure-reason.ts +7 -0
- package/dist/cli/template-assets/packages/{queue-runtime/src/index.ts → queue/src/shared/redis/connection.ts} +2 -15
- package/dist/cli/template-assets/packages/queue/src/types/redis/connection.ts +6 -0
- package/dist/cli/template-assets/packages/webhooks/src/index.ts +11 -0
- package/dist/cli/template-assets/packages/webhooks/src/shared/crypto/secret.ts +81 -0
- package/dist/cli/template-assets/packages/webhooks/src/shared/signing/headers.ts +43 -0
- package/dist/cli/template-assets/packages/webhooks/src/shared/url/deliverable.ts +58 -0
- package/dist/cli/template-assets/packages/webhooks/src/types/webhooks/job.ts +18 -0
- package/dist/cli/template-assets/packages/webhooks/test/webhooks.test.ts.tpl +69 -0
- package/dist/cli/template-assets/root/dot-dockerignore +88 -8
- package/dist/cli/template-assets/root/dot-oxlintrc.json +22 -0
- package/dist/cli/template-assets/root/lefthook.yml +32 -8
- package/dist/cli/template-assets/web/src/app/(app)/layout.tsx +2 -3
- package/dist/cli/template-assets/web/src/app/(auth)/login/page.tsx +1 -1
- package/dist/cli/template-assets/web/src/app/page.tsx +1 -0
- package/dist/cli/template-assets/web/src/{lib/api-client.ts → shared/api/client.ts} +11 -8
- package/dist/cli/template-assets/web/src/{lib/server-auth.ts → shared/auth/server.ts} +1 -2
- package/dist/cli/template-assets/web/src/types/api.ts +0 -15
- package/dist/cli/template-assets/webhooks/api/src/modules/webhooks/controller.ts +81 -0
- package/dist/cli/template-assets/webhooks/api/src/modules/webhooks/dto/create-endpoint.dto.ts +25 -0
- package/dist/cli/template-assets/webhooks/api/src/modules/webhooks/dto/endpoint.dto.ts +28 -0
- package/dist/cli/template-assets/webhooks/api/src/modules/webhooks/module.ts +27 -0
- package/dist/cli/template-assets/webhooks/api/src/modules/webhooks/repository.ts +147 -0
- package/dist/cli/template-assets/webhooks/api/src/modules/webhooks/service.ts +119 -0
- package/dist/cli/template-assets/webhooks/api/src/types/webhooks/endpoint.ts +26 -0
- package/dist/cli/template-assets/webhooks/worker/src/env.ts +18 -0
- package/dist/cli/template-assets/webhooks/worker/src/modules/queue/dispatcher.ts +119 -0
- package/dist/cli/template-assets/webhooks/worker/src/modules/queue/module.ts +16 -0
- package/dist/cli/template-assets/webhooks/worker/src/modules/queue/processor.ts +176 -0
- package/dist/cli/template-assets/webhooks/worker/src/modules/queue/repository.ts +187 -0
- package/dist/cli/template-assets/webhooks/worker/src/shared/http/deliver.ts +41 -0
- package/dist/cli/template-assets/webhooks/worker/src/types/webhooks/dispatch.ts +26 -0
- package/dist/cli/template-assets/worker/src/app.module.ts +14 -0
- package/dist/cli/template-assets/worker/src/main.ts +24 -0
- package/dist/cli/template-assets/worker/src/modules/queue/processor.ts +26 -3
- package/dist/cli/template-assets/worker/src/modules/queue/retry.ts +22 -7
- package/dist/cli/template-assets/worker/test/retry.test.ts.tpl +13 -1
- package/dist/cli/template-assets/worker-messaging/messaging-api-service.ts +6 -6
- package/dist/cli/template-assets/worker-messaging/src/env.ts +1 -1
- package/dist/cli/template-assets/worker-messaging/src/modules/messaging/service.ts +2 -4
- package/dist/cli/template-assets/worker-messaging/src/modules/queue/module.ts +1 -1
- package/dist/cli/template-assets/worker-messaging/src/modules/queue/processor.ts +32 -10
- package/dist/cli.js +631 -314
- package/dist/{index-CNlb6WNr.d.ts → index-Bl4Ka1Wr.d.ts} +2 -2
- package/dist/{index-I_Nx5SsQ.d.cts → index-CBue43h0.d.cts} +2 -2
- package/dist/{index-B_byXBRW.d.ts → index-cKCKFKLi.d.cts} +181 -5
- package/dist/{index-B_byXBRW.d.cts → index-cKCKFKLi.d.ts} +181 -5
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/messaging/index.cjs +1 -1
- package/dist/messaging/index.d.cts +1 -1
- package/dist/messaging/index.d.ts +1 -1
- package/dist/messaging/index.js +1 -1
- package/dist/sso/client.d.cts +2 -2
- package/dist/sso/client.d.ts +2 -2
- package/dist/sso/index.cjs +72 -1
- package/dist/sso/index.cjs.map +1 -1
- package/dist/sso/index.d.cts +2 -2
- package/dist/sso/index.d.ts +2 -2
- package/dist/sso/index.js +72 -1
- package/dist/sso/index.js.map +1 -1
- package/dist/sso/nestjs.cjs +2 -2
- package/dist/sso/nestjs.d.cts +2 -2
- package/dist/sso/nestjs.d.ts +2 -2
- package/dist/sso/nestjs.js +2 -2
- package/dist/sso/resource.cjs +2 -2
- package/dist/sso/resource.d.cts +3 -3
- package/dist/sso/resource.d.ts +3 -3
- package/dist/sso/resource.js +2 -2
- package/dist/{verifier-BIBtPCVi.cjs → verifier-BYrFb8tg.cjs} +2 -2
- package/dist/{verifier-BIBtPCVi.cjs.map → verifier-BYrFb8tg.cjs.map} +1 -1
- package/dist/{verifier-DNdy5Ynw.js → verifier-DSvtdWuY.js} +2 -2
- package/dist/{verifier-DNdy5Ynw.js.map → verifier-DSvtdWuY.js.map} +1 -1
- package/dist/version-8Zc_uUvG.js +1 -0
- package/dist/{version-DDLRsahz.cjs → version-BMXokpna.cjs} +1 -1
- package/package.json +1 -1
- package/dist/cli/template-assets/api/src/errors/codes.ts +0 -17
- package/dist/cli/template-assets/api/src/errors/index.ts +0 -16
- package/dist/cli/template-assets/api/src/filters/exception.ts +0 -53
- package/dist/cli/template-assets/api/src/shared/exceptions.ts +0 -40
- package/dist/cli/template-assets/api/src/shared/response.ts +0 -31
- package/dist/cli/template-assets/api/src/telemetry.ts +0 -59
- package/dist/version-DHlIo_M1.js +0 -1
- /package/dist/cli/template-assets/web/src/{lib/auth-client.ts → shared/auth/client.ts} +0 -0
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Injectable,
|
|
3
|
+
// #if !telemetry
|
|
3
4
|
Logger,
|
|
5
|
+
// #endif
|
|
4
6
|
type OnModuleDestroy,
|
|
5
7
|
type OnModuleInit,
|
|
6
8
|
} from '@nestjs/common';
|
|
7
9
|
import { UnrecoverableError, Worker } from 'bullmq';
|
|
10
|
+
// #if telemetry
|
|
11
|
+
import { Telemetry } from 'franchising/telemetry';
|
|
12
|
+
import { observeWorker, runObservedJob } from '__ROCK_SCOPE__/observability';
|
|
13
|
+
// #endif
|
|
8
14
|
import {
|
|
9
15
|
createWorkerRedisConnection,
|
|
10
16
|
failureReason,
|
|
11
17
|
type QueueRedisConnection,
|
|
12
|
-
} from '__ROCK_SCOPE__/queue
|
|
18
|
+
} from '__ROCK_SCOPE__/queue';
|
|
13
19
|
import { __ROCK_WORKER_QUEUE_CONST__, queuePrefix } from '__ROCK_SCOPE__/jobs';
|
|
14
20
|
import { env } from '../../env';
|
|
15
21
|
import {
|
|
@@ -33,19 +39,33 @@ import { isRetryable } from './retry';
|
|
|
33
39
|
export class __ROCK_WORKER_CLASS__Processor
|
|
34
40
|
implements OnModuleInit, OnModuleDestroy
|
|
35
41
|
{
|
|
42
|
+
// #if !telemetry
|
|
36
43
|
private readonly logger = new Logger(__ROCK_WORKER_CLASS__Processor.name);
|
|
44
|
+
// #endif
|
|
37
45
|
private worker?: Worker;
|
|
38
46
|
private connection?: QueueRedisConnection;
|
|
39
47
|
|
|
48
|
+
// #if telemetry
|
|
40
49
|
constructor(
|
|
41
50
|
private readonly repository: __ROCK_WORKER_CLASS__Repository,
|
|
51
|
+
private readonly telemetry: Telemetry,
|
|
42
52
|
) {}
|
|
53
|
+
// #else
|
|
54
|
+
constructor(
|
|
55
|
+
private readonly repository: __ROCK_WORKER_CLASS__Repository,
|
|
56
|
+
) {}
|
|
57
|
+
// #endif
|
|
43
58
|
|
|
44
59
|
onModuleInit(): void {
|
|
45
60
|
this.connection = createWorkerRedisConnection(env.QUEUE_REDIS_URL);
|
|
61
|
+
|
|
46
62
|
this.worker = new Worker(
|
|
47
63
|
__ROCK_WORKER_QUEUE_CONST__,
|
|
64
|
+
// #if telemetry
|
|
65
|
+
(job) => runObservedJob(this.telemetry, job, () => this.process(job)),
|
|
66
|
+
// #else
|
|
48
67
|
(job) => this.process(job),
|
|
68
|
+
// #endif
|
|
49
69
|
{
|
|
50
70
|
connection: this.connection.client,
|
|
51
71
|
prefix: queuePrefix(
|
|
@@ -60,6 +80,9 @@ export class __ROCK_WORKER_CLASS__Processor
|
|
|
60
80
|
},
|
|
61
81
|
);
|
|
62
82
|
|
|
83
|
+
// #if telemetry
|
|
84
|
+
observeWorker(this.worker, this.telemetry);
|
|
85
|
+
// #else
|
|
63
86
|
this.worker.on('failed', (job, error) => {
|
|
64
87
|
this.logger.error(
|
|
65
88
|
JSON.stringify({
|
|
@@ -79,6 +102,7 @@ export class __ROCK_WORKER_CLASS__Processor
|
|
|
79
102
|
}),
|
|
80
103
|
);
|
|
81
104
|
});
|
|
105
|
+
// #endif
|
|
82
106
|
}
|
|
83
107
|
|
|
84
108
|
async onModuleDestroy(): Promise<void> {
|
|
@@ -95,9 +119,8 @@ export class __ROCK_WORKER_CLASS__Processor
|
|
|
95
119
|
* `UnrecoverableError` tira o job da fila na hora. Sem isso um
|
|
96
120
|
* payload invalido ficaria repetindo ate esgotar as tentativas.
|
|
97
121
|
*/
|
|
98
|
-
if (!isRetryable(error))
|
|
122
|
+
if (!isRetryable(error))
|
|
99
123
|
throw new UnrecoverableError(failureReason(error));
|
|
100
|
-
}
|
|
101
124
|
|
|
102
125
|
throw error;
|
|
103
126
|
}
|
|
@@ -1,17 +1,32 @@
|
|
|
1
|
+
/** Status HTTP de um erro: `HttpError`/`HttpException` ou `{ status }`. */
|
|
2
|
+
function statusOf(error: unknown): number | undefined {
|
|
3
|
+
const candidate = error as
|
|
4
|
+
| { status?: unknown; getStatus?: () => number }
|
|
5
|
+
| undefined;
|
|
6
|
+
|
|
7
|
+
if (typeof candidate?.getStatus === 'function') return candidate.getStatus();
|
|
8
|
+
|
|
9
|
+
return typeof candidate?.status === 'number' ? candidate.status : void 0;
|
|
10
|
+
}
|
|
11
|
+
|
|
1
12
|
/**
|
|
2
13
|
* Decide se vale tentar o job de novo.
|
|
3
14
|
*
|
|
4
15
|
* @remarks
|
|
5
|
-
* Erro de rede
|
|
6
|
-
*
|
|
7
|
-
*
|
|
16
|
+
* Erro de rede, 5xx, 408 e 429 tendem a passar sozinhos, entao vale retentar.
|
|
17
|
+
* Payload invalido (`TypeError`, o `ValidationFailed` do `franchising/http`) e
|
|
18
|
+
* os outros 4xx nao mudam com o tempo: retentar so queima as tentativas e
|
|
19
|
+
* atrasa a ida para a fila de falhas.
|
|
8
20
|
*/
|
|
9
21
|
export function isRetryable(error: unknown): boolean {
|
|
10
|
-
if (error instanceof TypeError)
|
|
22
|
+
if (error instanceof TypeError) return false;
|
|
23
|
+
|
|
24
|
+
if ((error as { code?: unknown } | undefined)?.code === 'ValidationFailed')
|
|
11
25
|
return false;
|
|
12
|
-
}
|
|
13
26
|
|
|
14
|
-
const
|
|
27
|
+
const status = statusOf(error);
|
|
28
|
+
|
|
29
|
+
if (status === void 0) return true;
|
|
15
30
|
|
|
16
|
-
return
|
|
31
|
+
return status >= 500 || status === 408 || status === 429;
|
|
17
32
|
}
|
|
@@ -7,6 +7,18 @@ describe('isRetryable', () => {
|
|
|
7
7
|
});
|
|
8
8
|
|
|
9
9
|
it('nao retenta payload invalido', () => {
|
|
10
|
-
expect(
|
|
10
|
+
expect(
|
|
11
|
+
isRetryable(Object.assign(new Error('bad'), { code: 'ValidationFailed' })),
|
|
12
|
+
).toBe(false);
|
|
13
|
+
|
|
14
|
+
expect(isRetryable(new TypeError('INVALID_JOB'))).toBe(false);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('retenta 5xx, 408 e 429, e nao os outros 4xx', () => {
|
|
18
|
+
for (const status of [500, 503, 408, 429])
|
|
19
|
+
expect(isRetryable({ status })).toBe(true);
|
|
20
|
+
|
|
21
|
+
for (const status of [400, 401, 404, 410])
|
|
22
|
+
expect(isRetryable({ status })).toBe(false);
|
|
11
23
|
});
|
|
12
24
|
});
|
|
@@ -2,29 +2,29 @@ import { Injectable, type OnModuleDestroy } from '@nestjs/common';
|
|
|
2
2
|
import { Queue } from 'bullmq';
|
|
3
3
|
import {
|
|
4
4
|
DEFAULT_JOB_OPTIONS,
|
|
5
|
-
|
|
5
|
+
EMAILS_QUEUE_NAME,
|
|
6
6
|
queuePrefix,
|
|
7
7
|
type SendEmailJob,
|
|
8
8
|
} from '__ROCK_SCOPE__/jobs';
|
|
9
|
-
import { createProducerRedisConnection } from '__ROCK_SCOPE__/queue
|
|
9
|
+
import { createProducerRedisConnection } from '__ROCK_SCOPE__/queue';
|
|
10
10
|
import { env } from '../../env';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
* Publica e-mails na fila do worker `
|
|
13
|
+
* Publica e-mails na fila do worker `emails`.
|
|
14
14
|
*
|
|
15
15
|
* @remarks
|
|
16
16
|
* A API nao fala com o provedor: enfileira e responde. O envio, as
|
|
17
17
|
* retentativas e a credencial da plataforma Messaging ficam em
|
|
18
|
-
* `apps/workers/
|
|
18
|
+
* `apps/workers/emails`, entao uma lentidao no provedor nao segura a
|
|
19
19
|
* requisicao de quem pediu o e-mail.
|
|
20
20
|
*/
|
|
21
21
|
@Injectable()
|
|
22
22
|
export class MessagingService implements OnModuleDestroy {
|
|
23
23
|
private readonly connection = createProducerRedisConnection(env.REDIS_URL);
|
|
24
24
|
|
|
25
|
-
private readonly queue = new Queue<SendEmailJob>(
|
|
25
|
+
private readonly queue = new Queue<SendEmailJob>(EMAILS_QUEUE_NAME, {
|
|
26
26
|
connection: this.connection.client,
|
|
27
|
-
prefix: queuePrefix(env.QUEUE_PREFIX,
|
|
27
|
+
prefix: queuePrefix(env.QUEUE_PREFIX, EMAILS_QUEUE_NAME),
|
|
28
28
|
defaultJobOptions: DEFAULT_JOB_OPTIONS,
|
|
29
29
|
});
|
|
30
30
|
|
|
@@ -8,7 +8,7 @@ export const env = cleanEnv(process.env, {
|
|
|
8
8
|
}),
|
|
9
9
|
QUEUE_REDIS_URL: str({ default: 'redis://localhost:6379' }),
|
|
10
10
|
QUEUE_PREFIX: str({ default: '__ROCK_PROJECT_SLUG__' }),
|
|
11
|
-
|
|
11
|
+
__ROCK_WORKER_CONCURRENCY_ENV__: num({ default: 5 }),
|
|
12
12
|
MESSAGING_API_KEY: str({ default: '' }),
|
|
13
13
|
MESSAGING_FROM: str({ default: 'nao-responda@rockfeller.com.br' }),
|
|
14
14
|
});
|
|
@@ -29,9 +29,8 @@ export class MessagingService {
|
|
|
29
29
|
* desenvolvimento o conteudo vai para o console, para testar links
|
|
30
30
|
* de login e redefinicao sem conta na plataforma.
|
|
31
31
|
*/
|
|
32
|
-
if (env.NODE_ENV === 'production')
|
|
32
|
+
if (env.NODE_ENV === 'production')
|
|
33
33
|
throw new Error('MESSAGING_API_KEY_REQUIRED');
|
|
34
|
-
}
|
|
35
34
|
|
|
36
35
|
this.logger.warn(
|
|
37
36
|
JSON.stringify({
|
|
@@ -52,8 +51,7 @@ export class MessagingService {
|
|
|
52
51
|
html: input.html,
|
|
53
52
|
});
|
|
54
53
|
|
|
55
|
-
if (error)
|
|
54
|
+
if (error)
|
|
56
55
|
throw new Error(`EMAIL_SEND_FAILED: ${error.code}`);
|
|
57
|
-
}
|
|
58
56
|
}
|
|
59
57
|
}
|
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Injectable,
|
|
3
|
+
// #if !telemetry
|
|
3
4
|
Logger,
|
|
5
|
+
// #endif
|
|
4
6
|
type OnModuleDestroy,
|
|
5
7
|
type OnModuleInit,
|
|
6
8
|
} from '@nestjs/common';
|
|
7
9
|
import { UnrecoverableError, Worker } from 'bullmq';
|
|
10
|
+
// #if telemetry
|
|
11
|
+
import { Telemetry } from 'franchising/telemetry';
|
|
12
|
+
import { observeWorker, runObservedJob } from '__ROCK_SCOPE__/observability';
|
|
13
|
+
// #endif
|
|
8
14
|
import {
|
|
9
15
|
createWorkerRedisConnection,
|
|
10
16
|
failureReason,
|
|
11
17
|
type QueueRedisConnection,
|
|
12
|
-
} from '__ROCK_SCOPE__/queue
|
|
18
|
+
} from '__ROCK_SCOPE__/queue';
|
|
13
19
|
import {
|
|
14
|
-
|
|
20
|
+
__ROCK_WORKER_QUEUE_CONST__,
|
|
15
21
|
queuePrefix,
|
|
16
22
|
type SendEmailJob,
|
|
17
23
|
} from '__ROCK_SCOPE__/jobs';
|
|
@@ -33,15 +39,14 @@ function parseSendEmailJob(data: unknown): SendEmailJob {
|
|
|
33
39
|
typeof job?.to !== 'string' ||
|
|
34
40
|
typeof job.subject !== 'string' ||
|
|
35
41
|
typeof job.html !== 'string'
|
|
36
|
-
)
|
|
42
|
+
)
|
|
37
43
|
throw new TypeError('INVALID_EMAIL_JOB');
|
|
38
|
-
}
|
|
39
44
|
|
|
40
45
|
return { to: job.to, subject: job.subject, html: job.html };
|
|
41
46
|
}
|
|
42
47
|
|
|
43
48
|
/**
|
|
44
|
-
* Consumidor da fila `
|
|
49
|
+
* Consumidor da fila `__ROCK_WORKER_QUEUE__`.
|
|
45
50
|
*
|
|
46
51
|
* @remarks
|
|
47
52
|
* A API so publica o e-mail; o envio, as retentativas e a credencial da
|
|
@@ -51,21 +56,35 @@ function parseSendEmailJob(data: unknown): SendEmailJob {
|
|
|
51
56
|
*/
|
|
52
57
|
@Injectable()
|
|
53
58
|
export class MessagingProcessor implements OnModuleInit, OnModuleDestroy {
|
|
59
|
+
// #if !telemetry
|
|
54
60
|
private readonly logger = new Logger(MessagingProcessor.name);
|
|
61
|
+
// #endif
|
|
55
62
|
private worker?: Worker;
|
|
56
63
|
private connection?: QueueRedisConnection;
|
|
57
64
|
|
|
65
|
+
// #if telemetry
|
|
66
|
+
constructor(
|
|
67
|
+
private readonly messaging: MessagingService,
|
|
68
|
+
private readonly telemetry: Telemetry,
|
|
69
|
+
) {}
|
|
70
|
+
// #else
|
|
58
71
|
constructor(private readonly messaging: MessagingService) {}
|
|
72
|
+
// #endif
|
|
59
73
|
|
|
60
74
|
onModuleInit(): void {
|
|
61
75
|
this.connection = createWorkerRedisConnection(env.QUEUE_REDIS_URL);
|
|
76
|
+
|
|
62
77
|
this.worker = new Worker(
|
|
63
|
-
|
|
78
|
+
__ROCK_WORKER_QUEUE_CONST__,
|
|
79
|
+
// #if telemetry
|
|
80
|
+
(job) => runObservedJob(this.telemetry, job, () => this.process(job)),
|
|
81
|
+
// #else
|
|
64
82
|
(job) => this.process(job),
|
|
83
|
+
// #endif
|
|
65
84
|
{
|
|
66
85
|
connection: this.connection.client,
|
|
67
|
-
prefix: queuePrefix(env.QUEUE_PREFIX,
|
|
68
|
-
concurrency: env.
|
|
86
|
+
prefix: queuePrefix(env.QUEUE_PREFIX, __ROCK_WORKER_QUEUE_CONST__),
|
|
87
|
+
concurrency: env.__ROCK_WORKER_CONCURRENCY_ENV__,
|
|
69
88
|
limiter: { max: RATE_LIMIT_PER_SECOND, duration: 1000 },
|
|
70
89
|
lockDuration: LOCK_DURATION_MS,
|
|
71
90
|
stalledInterval: STALLED_INTERVAL_MS,
|
|
@@ -73,6 +92,9 @@ export class MessagingProcessor implements OnModuleInit, OnModuleDestroy {
|
|
|
73
92
|
},
|
|
74
93
|
);
|
|
75
94
|
|
|
95
|
+
// #if telemetry
|
|
96
|
+
observeWorker(this.worker, this.telemetry);
|
|
97
|
+
// #else
|
|
76
98
|
this.worker.on('failed', (job, error) => {
|
|
77
99
|
this.logger.error(
|
|
78
100
|
JSON.stringify({
|
|
@@ -92,6 +114,7 @@ export class MessagingProcessor implements OnModuleInit, OnModuleDestroy {
|
|
|
92
114
|
}),
|
|
93
115
|
);
|
|
94
116
|
});
|
|
117
|
+
// #endif
|
|
95
118
|
}
|
|
96
119
|
|
|
97
120
|
async onModuleDestroy(): Promise<void> {
|
|
@@ -103,9 +126,8 @@ export class MessagingProcessor implements OnModuleInit, OnModuleDestroy {
|
|
|
103
126
|
try {
|
|
104
127
|
await this.messaging.sendEmail(parseSendEmailJob(job.data));
|
|
105
128
|
} catch (error) {
|
|
106
|
-
if (!isRetryable(error))
|
|
129
|
+
if (!isRetryable(error))
|
|
107
130
|
throw new UnrecoverableError(failureReason(error));
|
|
108
|
-
}
|
|
109
131
|
|
|
110
132
|
throw error;
|
|
111
133
|
}
|