| import { TemporalModule } from 'nestjs-temporal-core'; |
| import { socialIntegrationList } from '@gitroom/nestjs-libraries/integrations/integration.manager'; |
|
|
| export const getTemporalModule = ( |
| isWorkers: boolean, |
| path?: string, |
| activityClasses?: any[] |
| ) => { |
| |
| |
| |
| |
| const excludeQueues = (process.env.EXCLUDE_QUEUE || '') |
| .split(',') |
| .map((s) => s.trim()) |
| .filter(Boolean); |
|
|
| |
| |
| |
| const divider = Math.max( |
| 1, |
| Number(process.env.WORKER_CONCURRENCY_DIVIDER) || 1 |
| ); |
|
|
| return TemporalModule.register({ |
| isGlobal: true, |
| connection: { |
| address: process.env.TEMPORAL_ADDRESS || 'localhost:7233', |
| ...(process.env.TEMPORAL_TLS === 'true' ? { tls: true } : {}), |
| ...(process.env.TEMPORAL_API_KEY |
| ? { apiKey: process.env.TEMPORAL_API_KEY } |
| : {}), |
| namespace: process.env.TEMPORAL_NAMESPACE || 'default', |
| }, |
| taskQueue: 'main', |
| logLevel: 'error', |
| ...(isWorkers |
| ? { |
| workers: [ |
| { identifier: 'main', maxConcurrentJob: undefined }, |
| ...socialIntegrationList, |
| ] |
| .filter((f) => f.identifier.indexOf('-') === -1) |
| .map((integration) => ({ |
| integration, |
| taskQueue: integration.identifier.split('-')[0], |
| })) |
| .filter(({ taskQueue }) => !excludeQueues.includes(taskQueue)) |
| .map(({ integration, taskQueue }) => { |
| |
| |
| |
| |
| const concurrency = integration.maxConcurrentJob |
| ? Math.max( |
| 1, |
| Math.floor(integration.maxConcurrentJob / divider) |
| ) |
| : undefined; |
|
|
| return { |
| taskQueue, |
| workflowsPath: path!, |
| activityClasses: activityClasses!, |
| autoStart: true, |
| ...(concurrency |
| ? { |
| workerOptions: { |
| maxConcurrentActivityTaskExecutions: concurrency, |
| }, |
| } |
| : { |
| workerOptions: { |
| maxConcurrentActivityTaskExecutions: 1000000, |
| }, |
| }), |
| }; |
| }), |
| } |
| : {}), |
| }); |
| }; |
|
|