Browse Source

feat: enum for job types

Signed-off-by: mertmit <mertmit99@gmail.com>
feat/export-nest
mertmit 2 years ago
parent
commit
ea483158dd
  1. 5
      packages/nocodb-nest/src/interface/Jobs.ts
  2. 9
      packages/nocodb-nest/src/modules/jobs/at-import/at-import.controller.ts
  3. 3
      packages/nocodb-nest/src/modules/jobs/at-import/at-import.processor.ts
  4. 3
      packages/nocodb-nest/src/modules/jobs/export-import/duplicate.controller.ts
  5. 3
      packages/nocodb-nest/src/modules/jobs/export-import/duplicate.processor.ts
  6. 2
      packages/nocodb-nest/src/modules/jobs/export-import/export.service.ts
  7. 5
      packages/nocodb-nest/src/modules/jobs/fallback-queue.service.ts

5
packages/nocodb-nest/src/interface/Jobs.ts

@ -0,0 +1,5 @@
export enum JobTypes {
DuplicateBase = 'duplicate-base',
DuplicateModel = 'duplicate-model',
AtImport = 'at-import',
}

9
packages/nocodb-nest/src/modules/jobs/at-import/at-import.controller.ts

@ -1,12 +1,13 @@
import { InjectQueue } from '@nestjs/bull'; import { InjectQueue } from '@nestjs/bull';
import { Controller, HttpCode, Post, Request, UseGuards } from '@nestjs/common'; import { Controller, HttpCode, Post, Request, UseGuards } from '@nestjs/common';
import { Queue } from 'bull';
import { GlobalGuard } from '../../../guards/global/global.guard'; import { GlobalGuard } from '../../../guards/global/global.guard';
import { ExtractProjectIdMiddleware } from '../../../middlewares/extract-project-id/extract-project-id.middleware'; import { ExtractProjectIdMiddleware } from '../../../middlewares/extract-project-id/extract-project-id.middleware';
import { Queue } from 'bull';
import { SyncSource } from '../../../models'; import { SyncSource } from '../../../models';
import { NcError } from '../../../helpers/catchError'; import { NcError } from '../../../helpers/catchError';
import { QueueService } from '../fallback-queue.service'; import { QueueService } from '../fallback-queue.service';
import { JobsService } from '../jobs.service'; import { JobsService } from '../jobs.service';
import { JobTypes } from '../../../interface/Jobs';
@Controller() @Controller()
@UseGuards(ExtractProjectIdMiddleware, GlobalGuard) @UseGuards(ExtractProjectIdMiddleware, GlobalGuard)
@ -25,7 +26,7 @@ export class AtImportController {
@Post('/api/v1/db/meta/import/airtable') @Post('/api/v1/db/meta/import/airtable')
@HttpCode(200) @HttpCode(200)
async importAirtable(@Request() req) { async importAirtable(@Request() req) {
const job = await this.activeQueue.add('at-import', { const job = await this.activeQueue.add(JobTypes.AtImport, {
...req.body, ...req.body,
}); });
@ -35,7 +36,7 @@ export class AtImportController {
@Post('/api/v1/db/meta/syncs/:syncId/trigger') @Post('/api/v1/db/meta/syncs/:syncId/trigger')
@HttpCode(200) @HttpCode(200)
async triggerSync(@Request() req) { 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); const fnd = jobs.find((j) => j.data.syncId === req.params.syncId);
if (fnd) { if (fnd) {
@ -55,7 +56,7 @@ export class AtImportController {
baseURL = `http://localhost:${process.env.PORT || 8080}`; 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, syncId: req.params.syncId,
...(syncSource?.details || {}), ...(syncSource?.details || {}),
projectId: syncSource.project_id, projectId: syncSource.project_id,

3
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 { ViewsService } from '../../../services/views.service';
import { FormsService } from '../../../services/forms.service'; import { FormsService } from '../../../services/forms.service';
import { JobsEventService } from '../jobs-event.service'; import { JobsEventService } from '../jobs-event.service';
import { JobTypes } from '../../../interface/Jobs';
import FetchAT from './helpers/fetchAT'; import FetchAT from './helpers/fetchAT';
import { importData, importLTARData } from './helpers/readAndProcessData'; import { importData, importLTARData } from './helpers/readAndProcessData';
import EntityMap from './helpers/EntityMap'; import EntityMap from './helpers/EntityMap';
@ -101,7 +102,7 @@ export class AtImportProcessor {
private readonly jobsEventService: JobsEventService, private readonly jobsEventService: JobsEventService,
) {} ) {}
@Process('at-import') @Process(JobTypes.AtImport)
async job(job: Job) { async job(job: Job) {
const syncDB = job.data; const syncDB = job.data;

3
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 { Base, Project } from '../../../models';
import { generateUniqueName } from '../../../helpers/exportImportHelpers'; import { generateUniqueName } from '../../../helpers/exportImportHelpers';
import { QueueService } from '../fallback-queue.service'; import { QueueService } from '../fallback-queue.service';
import { JobTypes } from '../../../interface/Jobs';
@Controller() @Controller()
@UseGuards(ExtractProjectIdMiddleware, GlobalGuard) @UseGuards(ExtractProjectIdMiddleware, GlobalGuard)
@ -67,7 +68,7 @@ export class DuplicateController {
user: { id: req.user.id }, user: { id: req.user.id },
}); });
const job = await this.activeQueue.add('duplicate', { const job = await this.activeQueue.add(JobTypes.DuplicateBase, {
projectId: project.id, projectId: project.id,
baseId: base.id, baseId: base.id,
dupProjectId: dupProject.id, dupProjectId: dupProject.id,

3
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 { ProjectsService } from '../../../services/projects.service';
import { findWithIdentifier } from '../../../helpers/exportImportHelpers'; import { findWithIdentifier } from '../../../helpers/exportImportHelpers';
import { BulkDataAliasService } from '../../../services/bulk-data-alias.service'; import { BulkDataAliasService } from '../../../services/bulk-data-alias.service';
import { JobTypes } from '../../../interface/Jobs';
import { ExportService } from './export.service'; import { ExportService } from './export.service';
import { ImportService } from './import.service'; import { ImportService } from './import.service';
import type { LinkToAnotherRecordColumn } from '../../../models'; import type { LinkToAnotherRecordColumn } from '../../../models';
@ -21,7 +22,7 @@ export class DuplicateProcessor {
private readonly bulkDataService: BulkDataAliasService, private readonly bulkDataService: BulkDataAliasService,
) {} ) {}
@Process('duplicate') @Process(JobTypes.DuplicateBase)
async duplicateBase(job: Job) { async duplicateBase(job: Job) {
const { projectId, baseId, dupProjectId, req } = job.data; const { projectId, baseId, dupProjectId, req } = job.data;

2
packages/nocodb-nest/src/modules/jobs/export-import/export.service.ts

@ -172,7 +172,6 @@ export class ExportService {
} }
serializedModels.push({ serializedModels.push({
entity: 'model',
model: { model: {
id: idMap.get(model.id), id: idMap.get(model.id),
prefix: project.prefix, prefix: project.prefix,
@ -545,7 +544,6 @@ export class ExportService {
const exportData = { const exportData = {
id: `${project.id}::${base.id}`, id: `${project.id}::${base.id}`,
entity: 'base',
models: exportedModels, models: exportedModels,
}; };

5
packages/nocodb-nest/src/modules/jobs/fallback-queue.service.ts

@ -1,6 +1,7 @@
import { Injectable } from '@nestjs/common'; import { Injectable } from '@nestjs/common';
import PQueue from 'p-queue'; import PQueue from 'p-queue';
import Emittery from 'emittery'; import Emittery from 'emittery';
import { JobTypes } from '../../interface/Jobs';
import { DuplicateProcessor } from './export-import/duplicate.processor'; import { DuplicateProcessor } from './export-import/duplicate.processor';
import { JobsEventService } from './jobs-event.service'; import { JobsEventService } from './jobs-event.service';
import { AtImportProcessor } from './at-import/at-import.processor'; import { AtImportProcessor } from './at-import/at-import.processor';
@ -54,11 +55,11 @@ export class QueueService {
} }
jobMap = { jobMap = {
duplicate: { [JobTypes.DuplicateBase]: {
this: this.duplicateProcessor, this: this.duplicateProcessor,
fn: this.duplicateProcessor.duplicateBase, fn: this.duplicateProcessor.duplicateBase,
}, },
'at-import': { [JobTypes.AtImport]: {
this: this.atImportProcessor, this: this.atImportProcessor,
fn: this.atImportProcessor.job, fn: this.atImportProcessor.job,
}, },

Loading…
Cancel
Save