Browse Source

feat: use a separate queue and job for progress (#2170)

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/2175/head
Pranav C 3 years ago committed by GitHub
parent
commit
36859d71e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      packages/nocodb/src/lib/noco-jobs/JobsMgr.ts
  2. 42
      packages/nocodb/src/lib/noco/meta/api/sync/importApis.ts

8
packages/nocodb/src/lib/noco-jobs/JobsMgr.ts

@ -42,7 +42,9 @@ export default abstract class JobsMgr {
}
protected async invokeSuccessCbks(jobName: string, payload: any) {
await Promise.all(this.successCbks?.[jobName]?.map(cb => cb(payload)));
await Promise.all(
this.successCbks?.[jobName]?.map(cb => cb(payload)) || []
);
}
protected async invokeFailureCbks(
jobName: string,
@ -50,7 +52,7 @@ export default abstract class JobsMgr {
error?: Error
) {
await Promise.all(
this.failureCbks?.[jobName]?.map(cb => cb(payload, error))
this.failureCbks?.[jobName]?.map(cb => cb(payload, error)) || []
);
}
protected async invokeProgressCbks(
@ -59,7 +61,7 @@ export default abstract class JobsMgr {
data?: any
) {
await Promise.all(
this.progressCbks?.[jobName]?.map(cb => cb(payload, data))
this.progressCbks?.[jobName]?.map(cb => cb(payload, data)) || []
);
}
}

42
packages/nocodb/src/lib/noco/meta/api/sync/importApis.ts

@ -9,6 +9,7 @@ import SyncSource from '../../../../noco-models/SyncSource';
import Noco from '../../../Noco';
import * as jwt from 'jsonwebtoken';
const AIRTABLE_IMPORT_JOB = 'AIRTABLE_IMPORT_JOB';
const AIRTABLE_PROGRESS_JOB = 'AIRTABLE_PROGRESS_JOB';
enum SyncStatus {
PROGRESS = 'PROGRESS',
@ -17,24 +18,45 @@ enum SyncStatus {
}
export default (router: Router, clients: { [id: string]: Socket }) => {
// add importer job handler and progress notification job handler
NocoJobs.jobsMgr.addJobWorker(AIRTABLE_IMPORT_JOB, job);
NocoJobs.jobsMgr.addJobWorker(
AIRTABLE_PROGRESS_JOB,
({ payload, progress }) => {
clients?.[payload?.id]?.emit('progress', {
msg: progress?.msg,
level: progress?.level,
status: progress?.status
});
}
);
NocoJobs.jobsMgr.addProgressCbk(AIRTABLE_IMPORT_JOB, (payload, progress) => {
clients?.[payload?.id]?.emit('progress', {
msg: progress?.msg,
level: progress?.level,
status: SyncStatus.PROGRESS
NocoJobs.jobsMgr.add(AIRTABLE_PROGRESS_JOB, {
payload,
progress: {
msg: progress?.msg,
level: progress?.level,
status: progress?.status
}
});
});
NocoJobs.jobsMgr.addSuccessCbk(AIRTABLE_IMPORT_JOB, payload => {
clients?.[payload?.id]?.emit('progress', {
msg: 'Complete!',
status: SyncStatus.COMPLETED
NocoJobs.jobsMgr.add(AIRTABLE_PROGRESS_JOB, {
payload,
progress: {
msg: 'Complete!',
status: SyncStatus.COMPLETED
}
});
});
NocoJobs.jobsMgr.addFailureCbk(AIRTABLE_IMPORT_JOB, (payload, error: any) => {
clients?.[payload?.id]?.emit('progress', {
msg: error?.message || 'Failed due to some internal error',
status: SyncStatus.FAILED
NocoJobs.jobsMgr.add(AIRTABLE_PROGRESS_JOB, {
payload,
progress: {
msg: error?.message || 'Failed due to some internal error',
status: SyncStatus.FAILED
}
});
});

Loading…
Cancel
Save