Browse Source

fix: airtable import - use the correct job reference

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/5444/head
Pranav C 2 years ago
parent
commit
fcb42aaaec
  1. 22
      packages/nocodb-nest/src/modules/import/import.controller.ts

22
packages/nocodb-nest/src/modules/import/import.controller.ts

@ -7,9 +7,9 @@ import { ExtractProjectIdMiddleware } from '../../middlewares/extract-project-id
import { SyncSource } from '../../models'; import { SyncSource } from '../../models';
import NocoJobs from '../../jobs/NocoJobs'; import NocoJobs from '../../jobs/NocoJobs';
import { SocketService } from '../../services/client/socket.service'; import { SocketService } from '../../services/client/socket.service';
import airtableSyncJob from '../sync/helpers/job';
import { ImportService } from './import.service'; import { ImportService } from './import.service';
import type { AirtableSyncConfig } from '../sync/helpers/job'; import type { AirtableSyncConfig } from '../sync/helpers/job';
import airtableSyncJob from '../sync/helpers/job';
import type { Server } from 'socket.io'; import type { Server } from 'socket.io';
@ -22,17 +22,13 @@ enum SyncStatus {
FAILED = 'FAILED', FAILED = 'FAILED',
} }
const jobs = []; const initJob = (sv: Server, jobs: { [p: string]: { last_message: any } }) => {
const initJob = (sv: Server, jobs: { [p: string]: { last_message: any } }, socketService: SocketService) => {
// add importer job handler and progress notification job handler // add importer job handler and progress notification job handler
NocoJobs.jobsMgr.addJobWorker( NocoJobs.jobsMgr.addJobWorker(AIRTABLE_IMPORT_JOB, airtableSyncJob);
AIRTABLE_IMPORT_JOB,
airtableSyncJob
);
NocoJobs.jobsMgr.addJobWorker( NocoJobs.jobsMgr.addJobWorker(
AIRTABLE_PROGRESS_JOB, AIRTABLE_PROGRESS_JOB,
({ payload, progress }) => { ({ payload, progress }) => {
socketService.io.to(payload?.id).emit('progress', { sv.to(payload?.id).emit('progress', {
msg: progress?.msg, msg: progress?.msg,
level: progress?.level, level: progress?.level,
status: progress?.status, status: progress?.status,
@ -101,7 +97,7 @@ export class ImportController {
@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) {
if (req.params.syncId in jobs) { if (req.params.syncId in this.socketService.jobs) {
NcError.badRequest('Sync already in progress'); NcError.badRequest('Sync already in progress');
} }
@ -131,7 +127,7 @@ export class ImportController {
}); });
}, 1000); }, 1000);
jobs[req.params.syncId] = { this.socketService.jobs[req.params.syncId] = {
last_message: { last_message: {
msg: 'Sync started', msg: 'Sync started',
}, },
@ -142,13 +138,13 @@ export class ImportController {
@Post('/api/v1/db/meta/syncs/:syncId/abort') @Post('/api/v1/db/meta/syncs/:syncId/abort')
@HttpCode(200) @HttpCode(200)
async abortImport(@Request() req) { async abortImport(@Request() req) {
if (req.params.syncId in jobs) { if (req.params.syncId in this.socketService.jobs) {
delete jobs[req.params.syncId]; delete this.socketService.jobs[req.params.syncId];
} }
return {}; return {};
} }
async onModuleInit() { async onModuleInit() {
initJob(this.socketService.io, this.socketService.jobs, this.socketService); initJob(this.socketService.io, this.socketService.jobs);
} }
} }

Loading…
Cancel
Save