-
-
Couldn't load subscription status.
- Fork 1.1k
feat: separate queue jobs from consumers for configurable processing #1968
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
boris-w
wants to merge
2
commits into
develop
Choose a base branch
from
feat/queue-consumer-separation
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
apps/nestjs-backend/src/features/attachments/attachments-crop.job.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import { InjectQueue } from '@nestjs/bullmq'; | ||
| import { Injectable } from '@nestjs/common'; | ||
| import { Queue } from 'bullmq'; | ||
|
|
||
| export interface IRecordImageJob { | ||
| bucket: string; | ||
| token: string; | ||
| path: string; | ||
| mimetype: string; | ||
| height?: number | null; | ||
| } | ||
|
|
||
| export const ATTACHMENTS_CROP_QUEUE = 'attachments-crop-queue'; | ||
|
|
||
| @Injectable() | ||
| export class AttachmentsCropJob { | ||
| constructor(@InjectQueue(ATTACHMENTS_CROP_QUEUE) public readonly queue: Queue<IRecordImageJob>) {} | ||
|
|
||
| addAttachmentCropImage(data: IRecordImageJob) { | ||
| return this.queue.add('attachment_crop_image', data); | ||
| } | ||
| } |
17 changes: 11 additions & 6 deletions
17
apps/nestjs-backend/src/features/attachments/attachments-crop.module.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,19 @@ | ||
| import { Module } from '@nestjs/common'; | ||
| import { EventJobModule } from '../../event-emitter/event-job/event-job.module'; | ||
| import { | ||
| ATTACHMENTS_CROP_QUEUE, | ||
| AttachmentsCropQueueProcessor, | ||
| } from './attachments-crop.processor'; | ||
| import { conditionalQueueProcessorProviders, QueueConsumerType } from '../../utils/queue'; | ||
| import { ATTACHMENTS_CROP_QUEUE, AttachmentsCropJob } from './attachments-crop.job'; | ||
| import { AttachmentsCropQueueProcessor } from './attachments-crop.processor'; | ||
| import { AttachmentsStorageModule } from './attachments-storage.module'; | ||
|
|
||
| @Module({ | ||
| providers: [AttachmentsCropQueueProcessor], | ||
| providers: [ | ||
| ...conditionalQueueProcessorProviders({ | ||
| consumer: QueueConsumerType.ImageCrop, | ||
| providers: [AttachmentsCropQueueProcessor], | ||
| }), | ||
| AttachmentsCropJob, | ||
| ], | ||
| imports: [EventJobModule.registerQueue(ATTACHMENTS_CROP_QUEUE), AttachmentsStorageModule], | ||
| exports: [AttachmentsCropQueueProcessor], | ||
| exports: [AttachmentsCropJob], | ||
| }) | ||
| export class AttachmentsCropModule {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...nestjs-backend/src/features/base/base-import-processor/base-import-attachments-csv.job.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import { InjectQueue } from '@nestjs/bullmq'; | ||
| import { Injectable } from '@nestjs/common'; | ||
| import { Queue } from 'bullmq'; | ||
|
|
||
| export interface IBaseImportAttachmentsCsvJob { | ||
| path: string; | ||
| userId: string; | ||
| } | ||
|
|
||
| export const BASE_IMPORT_ATTACHMENTS_CSV_QUEUE = 'base-import-attachments-csv-queue'; | ||
|
|
||
| @Injectable() | ||
| export class BaseImportAttachmentsCsvJob { | ||
| constructor( | ||
| @InjectQueue(BASE_IMPORT_ATTACHMENTS_CSV_QUEUE) | ||
| public readonly queue: Queue<IBaseImportAttachmentsCsvJob> | ||
| ) {} | ||
| } |
17 changes: 12 additions & 5 deletions
17
...tjs-backend/src/features/base/base-import-processor/base-import-attachments-csv.module.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,21 @@ | ||
| import { Module } from '@nestjs/common'; | ||
| import { EventJobModule } from '../../../event-emitter/event-job/event-job.module'; | ||
| import { conditionalQueueProcessorProviders, QueueConsumerType } from '../../../utils/queue'; | ||
| import { StorageModule } from '../../attachments/plugins/storage.module'; | ||
| import { | ||
| BaseImportAttachmentsCsvQueueProcessor, | ||
| BASE_IMPORT_ATTACHMENTS_CSV_QUEUE, | ||
| } from './base-import-attachments-csv.processor'; | ||
|
|
||
| BaseImportAttachmentsCsvJob, | ||
| } from './base-import-attachments-csv.job'; | ||
| import { BaseImportAttachmentsCsvQueueProcessor } from './base-import-attachments-csv.processor'; | ||
| @Module({ | ||
| providers: [BaseImportAttachmentsCsvQueueProcessor], | ||
| providers: [ | ||
| ...conditionalQueueProcessorProviders({ | ||
| consumer: QueueConsumerType.ImportExport, | ||
| providers: [BaseImportAttachmentsCsvQueueProcessor], | ||
| }), | ||
| BaseImportAttachmentsCsvJob, | ||
| ], | ||
| imports: [EventJobModule.registerQueue(BASE_IMPORT_ATTACHMENTS_CSV_QUEUE), StorageModule], | ||
| exports: [BaseImportAttachmentsCsvQueueProcessor], | ||
| exports: [BaseImportAttachmentsCsvJob], | ||
| }) | ||
| export class BaseImportAttachmentsCsvModule {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
apps/nestjs-backend/src/features/base/base-import-processor/base-import-attachments.job.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import { InjectQueue } from '@nestjs/bullmq'; | ||
| import { Injectable } from '@nestjs/common'; | ||
| import { Queue } from 'bullmq'; | ||
|
|
||
| export interface IBaseImportJob { | ||
| path: string; | ||
| userId: string; | ||
| } | ||
|
|
||
| export const BASE_IMPORT_ATTACHMENTS_QUEUE = 'base-import-attachments-queue'; | ||
|
|
||
| @Injectable() | ||
| export class BaseImportAttachmentsJob { | ||
| constructor( | ||
| @InjectQueue(BASE_IMPORT_ATTACHMENTS_QUEUE) public readonly queue: Queue<IBaseImportJob> | ||
| ) {} | ||
| } |
21 changes: 13 additions & 8 deletions
21
.../nestjs-backend/src/features/base/base-import-processor/base-import-attachments.module.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,28 @@ | ||
| import { Module } from '@nestjs/common'; | ||
| import { EventJobModule } from '../../../event-emitter/event-job/event-job.module'; | ||
| import { conditionalQueueProcessorProviders, QueueConsumerType } from '../../../utils/queue'; | ||
| import { StorageModule } from '../../attachments/plugins/storage.module'; | ||
| import { BASE_IMPORT_ATTACHMENTS_CSV_QUEUE } from './base-import-attachments-csv.job'; | ||
| import { BaseImportAttachmentsCsvModule } from './base-import-attachments-csv.module'; | ||
| import { | ||
| BaseImportAttachmentsCsvQueueProcessor, | ||
| BASE_IMPORT_ATTACHMENTS_CSV_QUEUE, | ||
| } from './base-import-attachments-csv.processor'; | ||
| import { | ||
| BASE_IMPORT_ATTACHMENTS_QUEUE, | ||
| BaseImportAttachmentsQueueProcessor, | ||
| } from './base-import-attachments.processor'; | ||
| BaseImportAttachmentsJob, | ||
| } from './base-import-attachments.job'; | ||
| import { BaseImportAttachmentsQueueProcessor } from './base-import-attachments.processor'; | ||
| @Module({ | ||
| providers: [BaseImportAttachmentsQueueProcessor, BaseImportAttachmentsCsvQueueProcessor], | ||
| providers: [ | ||
| ...conditionalQueueProcessorProviders({ | ||
| consumer: QueueConsumerType.ImportExport, | ||
| providers: [BaseImportAttachmentsQueueProcessor], | ||
| }), | ||
| BaseImportAttachmentsJob, | ||
| ], | ||
| imports: [ | ||
| EventJobModule.registerQueue(BASE_IMPORT_ATTACHMENTS_QUEUE), | ||
| EventJobModule.registerQueue(BASE_IMPORT_ATTACHMENTS_CSV_QUEUE), | ||
| StorageModule, | ||
| BaseImportAttachmentsCsvModule, | ||
| ], | ||
| exports: [BaseImportAttachmentsQueueProcessor, BaseImportAttachmentsCsvQueueProcessor], | ||
| exports: [BaseImportAttachmentsJob], | ||
| }) | ||
| export class BaseImportAttachmentsModule {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
apps/nestjs-backend/src/features/base/base-import-processor/base-import-csv.job.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| /* eslint-disable @typescript-eslint/naming-convention */ | ||
| import { InjectQueue } from '@nestjs/bullmq'; | ||
| import { Injectable } from '@nestjs/common'; | ||
| import type { IBaseJson } from '@teable/openapi'; | ||
| import { Queue } from 'bullmq'; | ||
| export interface IBaseImportCsvJob { | ||
| path: string; | ||
| userId: string; | ||
| tableIdMap: Record<string, string>; | ||
| fieldIdMap: Record<string, string>; | ||
| viewIdMap: Record<string, string>; | ||
| fkMap: Record<string, string>; | ||
| structure: IBaseJson; | ||
| } | ||
|
|
||
| export const BASE_IMPORT_CSV_QUEUE = 'base-import-csv-queue'; | ||
|
|
||
| @Injectable() | ||
| export class BaseImportCsvJob { | ||
| constructor( | ||
| @InjectQueue(BASE_IMPORT_CSV_QUEUE) public readonly queue: Queue<IBaseImportCsvJob> | ||
| ) {} | ||
| } |
16 changes: 12 additions & 4 deletions
16
apps/nestjs-backend/src/features/base/base-import-processor/base-import-csv.module.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,26 @@ | ||
| import { Module } from '@nestjs/common'; | ||
| import { EventJobModule } from '../../../event-emitter/event-job/event-job.module'; | ||
| import { conditionalQueueProcessorProviders, QueueConsumerType } from '../../../utils/queue'; | ||
| import { StorageModule } from '../../attachments/plugins/storage.module'; | ||
| import { BASE_IMPORT_ATTACHMENTS_CSV_QUEUE } from './base-import-attachments-csv.processor'; | ||
| import { BASE_IMPORT_CSV_QUEUE, BaseImportCsvQueueProcessor } from './base-import-csv.processor'; | ||
| import { BASE_IMPORT_ATTACHMENTS_CSV_QUEUE } from './base-import-attachments-csv.job'; | ||
| import { BASE_IMPORT_CSV_QUEUE, BaseImportCsvJob } from './base-import-csv.job'; | ||
| import { BaseImportCsvQueueProcessor } from './base-import-csv.processor'; | ||
| import { BaseImportJunctionCsvModule } from './base-import-junction-csv.module'; | ||
|
|
||
| @Module({ | ||
| providers: [BaseImportCsvQueueProcessor], | ||
| providers: [ | ||
| BaseImportCsvJob, | ||
| ...conditionalQueueProcessorProviders({ | ||
| consumer: QueueConsumerType.ImportExport, | ||
| providers: [BaseImportCsvQueueProcessor], | ||
| }), | ||
| ], | ||
| imports: [ | ||
| EventJobModule.registerQueue(BASE_IMPORT_CSV_QUEUE), | ||
| EventJobModule.registerQueue(BASE_IMPORT_ATTACHMENTS_CSV_QUEUE), | ||
| StorageModule, | ||
| BaseImportJunctionCsvModule, | ||
| ], | ||
| exports: [BaseImportCsvQueueProcessor], | ||
| exports: [BaseImportCsvJob], | ||
| }) | ||
| export class BaseImportCsvModule {} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method call should pass the data object directly to maintain consistency with the queue.add pattern used elsewhere in the codebase.