diff --git a/packages/nocodb-nest/src/interface/Jobs.ts b/packages/nocodb-nest/src/interface/Jobs.ts new file mode 100644 index 0000000000..31cafd5c71 --- /dev/null +++ b/packages/nocodb-nest/src/interface/Jobs.ts @@ -0,0 +1,5 @@ +export enum JobTypes { + DuplicateBase = 'duplicate-base', + DuplicateModel = 'duplicate-model', + AtImport = 'at-import', +} diff --git a/packages/nocodb-nest/src/modules/jobs/at-import/at-import.controller.ts b/packages/nocodb-nest/src/modules/jobs/at-import/at-import.controller.ts index b255318c1b..c4224347ba 100644 --- a/packages/nocodb-nest/src/modules/jobs/at-import/at-import.controller.ts +++ b/packages/nocodb-nest/src/modules/jobs/at-import/at-import.controller.ts @@ -1,12 +1,13 @@ import { InjectQueue } from '@nestjs/bull'; import { Controller, HttpCode, Post, Request, UseGuards } from '@nestjs/common'; +import { Queue } from 'bull'; import { GlobalGuard } from '../../../guards/global/global.guard'; import { ExtractProjectIdMiddleware } from '../../../middlewares/extract-project-id/extract-project-id.middleware'; -import { Queue } from 'bull'; import { SyncSource } from '../../../models'; import { NcError } from '../../../helpers/catchError'; import { QueueService } from '../fallback-queue.service'; import { JobsService } from '../jobs.service'; +import { JobTypes } from '../../../interface/Jobs'; @Controller() @UseGuards(ExtractProjectIdMiddleware, GlobalGuard) @@ -25,7 +26,7 @@ export class AtImportController { @Post('/api/v1/db/meta/import/airtable') @HttpCode(200) async importAirtable(@Request() req) { - const job = await this.activeQueue.add('at-import', { + const job = await this.activeQueue.add(JobTypes.AtImport, { ...req.body, }); @@ -35,7 +36,7 @@ export class AtImportController { @Post('/api/v1/db/meta/syncs/:syncId/trigger') @HttpCode(200) async triggerSync(@Request() req) { - const jobs = await this.jobsService.jobList('at-import'); + const jobs = await this.jobsService.jobList(JobTypes.AtImport); const fnd = jobs.find((j) => j.data.syncId === req.params.syncId); if (fnd) { @@ -55,7 +56,7 @@ export class AtImportController { baseURL = `http://localhost:${process.env.PORT || 8080}`; } - const job = await this.activeQueue.add('at-import', { + const job = await this.activeQueue.add(JobTypes.AtImport, { syncId: req.params.syncId, ...(syncSource?.details || {}), projectId: syncSource.project_id, diff --git a/packages/nocodb-nest/src/modules/jobs/at-import/at-import.processor.ts b/packages/nocodb-nest/src/modules/jobs/at-import/at-import.processor.ts index 0ab6e7e30c..310446babc 100644 --- a/packages/nocodb-nest/src/modules/jobs/at-import/at-import.processor.ts +++ b/packages/nocodb-nest/src/modules/jobs/at-import/at-import.processor.ts @@ -25,6 +25,7 @@ import { ViewColumnsService } from '../../../services/view-columns.service'; import { ViewsService } from '../../../services/views.service'; import { FormsService } from '../../../services/forms.service'; import { JobsEventService } from '../jobs-event.service'; +import { JobTypes } from '../../../interface/Jobs'; import FetchAT from './helpers/fetchAT'; import { importData, importLTARData } from './helpers/readAndProcessData'; import EntityMap from './helpers/EntityMap'; @@ -101,7 +102,7 @@ export class AtImportProcessor { private readonly jobsEventService: JobsEventService, ) {} - @Process('at-import') + @Process(JobTypes.AtImport) async job(job: Job) { const syncDB = job.data; diff --git a/packages/nocodb-nest/src/modules/jobs/export-import/duplicate.controller.ts b/packages/nocodb-nest/src/modules/jobs/export-import/duplicate.controller.ts index 2603518d34..6fadd198af 100644 --- a/packages/nocodb-nest/src/modules/jobs/export-import/duplicate.controller.ts +++ b/packages/nocodb-nest/src/modules/jobs/export-import/duplicate.controller.ts @@ -18,6 +18,7 @@ import { ProjectsService } from '../../../services/projects.service'; import { Base, Project } from '../../../models'; import { generateUniqueName } from '../../../helpers/exportImportHelpers'; import { QueueService } from '../fallback-queue.service'; +import { JobTypes } from '../../../interface/Jobs'; @Controller() @UseGuards(ExtractProjectIdMiddleware, GlobalGuard) @@ -67,7 +68,7 @@ export class DuplicateController { user: { id: req.user.id }, }); - const job = await this.activeQueue.add('duplicate', { + const job = await this.activeQueue.add(JobTypes.DuplicateBase, { projectId: project.id, baseId: base.id, dupProjectId: dupProject.id, diff --git a/packages/nocodb-nest/src/modules/jobs/export-import/duplicate.processor.ts b/packages/nocodb-nest/src/modules/jobs/export-import/duplicate.processor.ts index 4dfb74d127..635ddb0917 100644 --- a/packages/nocodb-nest/src/modules/jobs/export-import/duplicate.processor.ts +++ b/packages/nocodb-nest/src/modules/jobs/export-import/duplicate.processor.ts @@ -6,6 +6,7 @@ import { Base, Column, Model, Project } from '../../../models'; import { ProjectsService } from '../../../services/projects.service'; import { findWithIdentifier } from '../../../helpers/exportImportHelpers'; import { BulkDataAliasService } from '../../../services/bulk-data-alias.service'; +import { JobTypes } from '../../../interface/Jobs'; import { ExportService } from './export.service'; import { ImportService } from './import.service'; import type { LinkToAnotherRecordColumn } from '../../../models'; @@ -21,7 +22,7 @@ export class DuplicateProcessor { private readonly bulkDataService: BulkDataAliasService, ) {} - @Process('duplicate') + @Process(JobTypes.DuplicateBase) async duplicateBase(job: Job) { const { projectId, baseId, dupProjectId, req } = job.data; diff --git a/packages/nocodb-nest/src/modules/jobs/export-import/export.service.ts b/packages/nocodb-nest/src/modules/jobs/export-import/export.service.ts index a2e4157d50..23b3dd2fde 100644 --- a/packages/nocodb-nest/src/modules/jobs/export-import/export.service.ts +++ b/packages/nocodb-nest/src/modules/jobs/export-import/export.service.ts @@ -172,7 +172,6 @@ export class ExportService { } serializedModels.push({ - entity: 'model', model: { id: idMap.get(model.id), prefix: project.prefix, @@ -545,7 +544,6 @@ export class ExportService { const exportData = { id: `${project.id}::${base.id}`, - entity: 'base', models: exportedModels, }; diff --git a/packages/nocodb-nest/src/modules/jobs/fallback-queue.service.ts b/packages/nocodb-nest/src/modules/jobs/fallback-queue.service.ts index bd3c9ee4c5..5a5659480c 100644 --- a/packages/nocodb-nest/src/modules/jobs/fallback-queue.service.ts +++ b/packages/nocodb-nest/src/modules/jobs/fallback-queue.service.ts @@ -1,6 +1,7 @@ import { Injectable } from '@nestjs/common'; import PQueue from 'p-queue'; import Emittery from 'emittery'; +import { JobTypes } from '../../interface/Jobs'; import { DuplicateProcessor } from './export-import/duplicate.processor'; import { JobsEventService } from './jobs-event.service'; import { AtImportProcessor } from './at-import/at-import.processor'; @@ -54,11 +55,11 @@ export class QueueService { } jobMap = { - duplicate: { + [JobTypes.DuplicateBase]: { this: this.duplicateProcessor, fn: this.duplicateProcessor.duplicateBase, }, - 'at-import': { + [JobTypes.AtImport]: { this: this.atImportProcessor, fn: this.atImportProcessor.job, },