Browse Source

feat: enum for job types

Signed-off-by: mertmit <mertmit99@gmail.com>
feat/export-nest-dir-restructure
mertmit 2 years ago committed by starbirdtech383
parent
commit
700a642bcc
  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 { 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,

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 { 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;

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 { 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,

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 { 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;

2
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,
};

5
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,
},

Loading…
Cancel
Save