Browse Source

feat: derive active queue from jobs service

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/5608/head
mertmit 2 years ago
parent
commit
d2e87a9ec0
  1. 20
      packages/nocodb/src/modules/jobs/at-import/at-import.controller.ts
  2. 25
      packages/nocodb/src/modules/jobs/export-import/duplicate.controller.ts
  3. 2
      packages/nocodb/src/modules/jobs/jobs.service.ts

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

@ -1,32 +1,20 @@
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 { SyncSource } from '../../../models';
import { NcError } from '../../../helpers/catchError';
import { QueueService } from '../fallback-queue.service';
import { JobsService } from '../jobs.service';
import { JOBS_QUEUE, JobTypes } from '../../../interface/Jobs';
import { JobTypes } from '../../../interface/Jobs';
@Controller()
@UseGuards(ExtractProjectIdMiddleware, GlobalGuard)
export class AtImportController {
activeQueue;
constructor(
@InjectQueue(JOBS_QUEUE) private readonly jobsQueue: Queue,
private readonly fallbackQueueService: QueueService,
private readonly jobsService: JobsService,
) {
this.activeQueue = process.env.NC_REDIS_URL
? this.jobsQueue
: this.fallbackQueueService;
}
constructor(private readonly jobsService: JobsService) {}
@Post('/api/v1/db/meta/import/airtable')
@HttpCode(200)
async importAirtable(@Request() req) {
const job = await this.activeQueue.add(JobTypes.AtImport, {
const job = await this.jobsService.activeQueue.add(JobTypes.AtImport, {
...req.body,
});
@ -56,7 +44,7 @@ export class AtImportController {
baseURL = `http://localhost:${process.env.PORT || 8080}`;
}
const job = await this.activeQueue.add(JobTypes.AtImport, {
const job = await this.jobsService.activeQueue.add(JobTypes.AtImport, {
syncId: req.params.syncId,
...(syncSource?.details || {}),
projectId: syncSource.project_id,

25
packages/nocodb/src/modules/jobs/export-import/duplicate.controller.ts

@ -1,4 +1,3 @@
import { InjectQueue } from '@nestjs/bull';
import {
Body,
Controller,
@ -8,7 +7,6 @@ import {
Request,
UseGuards,
} from '@nestjs/common';
import { Queue } from 'bull';
import { GlobalGuard } from '../../../guards/global/global.guard';
import {
Acl,
@ -17,22 +15,16 @@ import {
import { ProjectsService } from '../../../services/projects.service';
import { Base, Model, Project } from '../../../models';
import { generateUniqueName } from '../../../helpers/exportImportHelpers';
import { QueueService } from '../fallback-queue.service';
import { JOBS_QUEUE, JobTypes } from '../../../interface/Jobs';
import { JobsService } from '../jobs.service';
import { JobTypes } from '../../../interface/Jobs';
@Controller()
@UseGuards(ExtractProjectIdMiddleware, GlobalGuard)
export class DuplicateController {
activeQueue;
constructor(
@InjectQueue(JOBS_QUEUE) private readonly jobsQueue: Queue,
private readonly fallbackQueueService: QueueService,
private readonly jobsService: JobsService,
private readonly projectsService: ProjectsService,
) {
this.activeQueue = process.env.NC_REDIS_URL
? this.jobsQueue
: this.fallbackQueueService;
}
) {}
@Post('/api/v1/db/meta/duplicate/:projectId/:baseId?')
@HttpCode(200)
@ -74,7 +66,7 @@ export class DuplicateController {
user: { id: req.user.id },
});
const job = await this.activeQueue.add(JobTypes.DuplicateBase, {
const job = await this.jobsService.activeQueue.add(JobTypes.DuplicateBase, {
projectId: project.id,
baseId: base.id,
dupProjectId: dupProject.id,
@ -123,7 +115,9 @@ export class DuplicateController {
models.map((p) => p.title),
);
const job = await this.activeQueue.add(JobTypes.DuplicateModel, {
const job = await this.jobsService.activeQueue.add(
JobTypes.DuplicateModel,
{
projectId: project.id,
baseId: base.id,
modelId: model.id,
@ -133,7 +127,8 @@ export class DuplicateController {
user: req.user,
clientIp: req.clientIp,
},
});
},
);
return { id: job.id, name: job.name };
}

2
packages/nocodb/src/modules/jobs/jobs.service.ts

@ -6,7 +6,7 @@ import { QueueService } from './fallback-queue.service';
@Injectable()
export class JobsService {
activeQueue;
public activeQueue;
constructor(
@InjectQueue(JOBS_QUEUE) private readonly jobsQueue: Queue,
private readonly fallbackQueueService: QueueService,

Loading…
Cancel
Save