Browse Source

Merge pull request #7502 from nocodb/nc-fix/at-logs

fix: at logs
pull/7499/head
Mert E 9 months ago committed by GitHub
parent
commit
ab679f08e2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 18
      packages/nocodb/src/modules/jobs/fallback/jobs-event.service.ts
  2. 17
      packages/nocodb/src/modules/jobs/jobs/at-import/helpers/EntityMap.ts
  3. 13
      packages/nocodb/src/modules/jobs/jobs/at-import/helpers/fetchAT.ts
  4. 2
      packages/nocodb/src/modules/jobs/jobs/at-import/helpers/readAndProcessData.ts
  5. 12
      packages/nocodb/src/modules/jobs/redis/jobs-event.service.ts
  6. 6
      packages/nocodb/src/modules/jobs/redis/jobs-redis.service.ts

18
packages/nocodb/src/modules/jobs/fallback/jobs-event.service.ts

@ -5,12 +5,14 @@ import {
Processor,
} from '@nestjs/bull';
import { Job } from 'bull';
import boxen from 'boxen';
import { EventEmitter2 } from '@nestjs/event-emitter';
import { Logger } from '@nestjs/common';
import { JobEvents, JOBS_QUEUE, JobStatus } from '~/interface/Jobs';
@Processor(JOBS_QUEUE)
export class JobsEventService {
protected logger = new Logger(JobsEventService.name);
constructor(private eventEmitter: EventEmitter2) {}
@OnQueueActive()
@ -23,18 +25,12 @@ export class JobsEventService {
@OnQueueFailed()
onFailed(job: Job, error: Error) {
console.error(
boxen(
`---- !! JOB FAILED !! ----\nid:${job.id}\nerror:${error.name} (${error.message})\n\nstack: ${error.stack}`,
{
padding: 1,
borderStyle: 'double',
borderColor: 'yellow',
},
),
this.logger.error(
`---- !! JOB FAILED !! ----\nid:${job.id}\nerror:${error.name} (${error.message})\n\nstack: ${error.stack}`,
);
this.eventEmitter.emit(JobEvents.STATUS, {
const newLocal = this;
newLocal.eventEmitter.emit(JobEvents.STATUS, {
id: job.id.toString(),
status: JobStatus.FAILED,
data: {

17
packages/nocodb/src/modules/jobs/jobs/at-import/helpers/EntityMap.ts

@ -1,5 +1,8 @@
import { Readable } from 'stream';
import sqlite3 from 'sqlite3';
import { Logger } from '@nestjs/common';
const logger = new Logger('EntityMap');
class EntityMap {
initialized: boolean;
@ -18,7 +21,7 @@ class EntityMap {
: 'mappingPlaceholder TEXT';
db.run(`CREATE TABLE mapping (${colStatement})`, (err) => {
if (err) {
console.log(err);
logger.log(err);
reject(err);
}
resolve(db);
@ -55,7 +58,7 @@ class EntityMap {
new Promise((resolve, reject) => {
this.db.run(`ALTER TABLE mapping ADD '${col}' TEXT;`, (err) => {
if (err) {
console.log(err);
logger.log(err);
reject(err);
}
this.cols.push(col);
@ -80,7 +83,7 @@ class EntityMap {
values,
(err) => {
if (err) {
console.log(err);
logger.log(err);
reject(err);
}
resolve(true);
@ -103,7 +106,7 @@ class EntityMap {
[val],
(err, rs) => {
if (err) {
console.log(err);
logger.log(err);
reject(err);
}
if (rs) {
@ -122,7 +125,7 @@ class EntityMap {
return new Promise((resolve, reject) => {
this.db.get(`SELECT COUNT(*) as count FROM mapping`, (err, rs) => {
if (err) {
console.log(err);
logger.log(err);
reject(err);
}
resolve(rs.count);
@ -153,7 +156,7 @@ class EntityMap {
} FROM mapping LIMIT ${limit} OFFSET ${offset}`,
(err, rs) => {
if (err) {
console.log(err);
logger.log(err);
reject(err);
}
for (let row of rs) {
@ -200,7 +203,7 @@ function processResponseRow(res: any) {
try {
res[key] = JSON.parse(res[key].replace('JSON::', ''));
} catch (e) {
console.log(e);
logger.log(e);
}
}
if (revertKey(key) !== key) {

13
packages/nocodb/src/modules/jobs/jobs/at-import/helpers/fetchAT.ts

@ -1,5 +1,8 @@
import { Logger } from '@nestjs/common';
import axios from 'axios';
const logger = new Logger('FetchAT');
const info: any = {
initialized: false,
};
@ -44,7 +47,7 @@ async function initialize(shareId, appId?: string) {
return response.data;
})
.catch((e) => {
console.log(e);
logger.log(e);
throw {
message:
'Invalid Shared Base ID :: Ensure www.airtable.com/<SharedBaseID> is accessible. Refer https://bit.ly/3x0OdXI for details',
@ -94,7 +97,7 @@ async function initialize(shareId, appId?: string) {
info.baseId = info.baseInfo.applicationId;
info.initialized = true;
} catch (e) {
console.log(e);
logger.log(e);
info.initialized = false;
if (e.message) {
throw e;
@ -135,7 +138,7 @@ async function read() {
return response.data;
})
.catch((e) => {
console.log(e);
logger.log(e);
throw {
message:
'Error Reading :: Ensure www.airtable.com/<SharedBaseID> is accessible. Refer https://bit.ly/3x0OdXI for details',
@ -202,7 +205,7 @@ async function readView(viewId) {
return response.data;
})
.catch((e) => {
console.log(e);
logger.log(e);
throw {
message:
'Error Reading View :: Ensure www.airtable.com/<SharedBaseID> is accessible. Refer https://bit.ly/3x0OdXI for details',
@ -252,7 +255,7 @@ async function readTemplate(templateId) {
return response.data;
})
.catch((e) => {
console.log(e);
logger.log(e);
throw {
message:
'Error Fetching :: Ensure www.airtable.com/templates/featured/<TemplateID> is accessible.',

2
packages/nocodb/src/modules/jobs/jobs/at-import/helpers/readAndProcessData.ts

@ -166,6 +166,7 @@ export async function importData({
logDetailed,
logWarning,
}).catch((e) => {
logger.error(e);
logWarning(`There were errors on reading '${table.title}' data :: ${e}`);
});
@ -187,6 +188,7 @@ export async function importData({
logDetailed,
logWarning,
}).catch((e) => {
logger.error(e);
logWarning(
`There were errors on importing '${table.title}' LTAR data :: ${e}`,
);

12
packages/nocodb/src/modules/jobs/redis/jobs-event.service.ts

@ -5,7 +5,6 @@ import {
Processor,
} from '@nestjs/bull';
import { Job } from 'bull';
import boxen from 'boxen';
import { EventEmitter2 } from '@nestjs/event-emitter';
import { Logger } from '@nestjs/common';
import { JobEvents, JOBS_QUEUE, JobStatus } from '~/interface/Jobs';
@ -28,15 +27,8 @@ export class JobsEventService {
@OnQueueFailed()
onFailed(job: Job, error: Error) {
this.logger.error(`Job ${job.id} failed with error ${error.message}`);
console.error(
boxen(
`---- !! JOB FAILED !! ----\nid:${job.id}\nerror:${error.name} (${error.message})\n\nstack: ${error.stack}`,
{
padding: 1,
borderStyle: 'double',
borderColor: 'yellow',
},
),
this.logger.error(
`---- !! JOB FAILED !! ----\nid:${job.id}\nerror:${error.name} (${error.message})\n\nstack: ${error.stack}`,
);
this.eventEmitter.emit(JobEvents.STATUS, {

6
packages/nocodb/src/modules/jobs/redis/jobs-redis.service.ts

@ -1,9 +1,11 @@
import { Injectable } from '@nestjs/common';
import { Injectable, Logger } from '@nestjs/common';
import Redis from 'ioredis';
import { InstanceTypes } from '~/interface/Jobs';
@Injectable()
export class JobsRedisService {
protected logger = new Logger(JobsRedisService.name);
private redisClient: Redis;
private redisSubscriber: Redis;
private unsubscribeCallbacks: { [key: string]: () => void } = {};
@ -42,7 +44,7 @@ export class JobsRedisService {
try {
this.redisClient.publish(channel, JSON.stringify(message));
} catch (e) {
console.error(e);
this.logger.error(e);
}
}
}

Loading…
Cancel
Save