Browse Source

fix: use logger instead of console

pull/7502/head
mertmit 11 months ago
parent
commit
138d230275
  1. 16
      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. 10
      packages/nocodb/src/modules/jobs/redis/jobs-event.service.ts
  5. 6
      packages/nocodb/src/modules/jobs/redis/jobs-redis.service.ts

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

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

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

@ -1,5 +1,8 @@
import { Readable } from 'stream'; import { Readable } from 'stream';
import sqlite3 from 'sqlite3'; import sqlite3 from 'sqlite3';
import { Logger } from '@nestjs/common';
const logger = new Logger('EntityMap');
class EntityMap { class EntityMap {
initialized: boolean; initialized: boolean;
@ -18,7 +21,7 @@ class EntityMap {
: 'mappingPlaceholder TEXT'; : 'mappingPlaceholder TEXT';
db.run(`CREATE TABLE mapping (${colStatement})`, (err) => { db.run(`CREATE TABLE mapping (${colStatement})`, (err) => {
if (err) { if (err) {
console.log(err); logger.log(err);
reject(err); reject(err);
} }
resolve(db); resolve(db);
@ -55,7 +58,7 @@ class EntityMap {
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
this.db.run(`ALTER TABLE mapping ADD '${col}' TEXT;`, (err) => { this.db.run(`ALTER TABLE mapping ADD '${col}' TEXT;`, (err) => {
if (err) { if (err) {
console.log(err); logger.log(err);
reject(err); reject(err);
} }
this.cols.push(col); this.cols.push(col);
@ -80,7 +83,7 @@ class EntityMap {
values, values,
(err) => { (err) => {
if (err) { if (err) {
console.log(err); logger.log(err);
reject(err); reject(err);
} }
resolve(true); resolve(true);
@ -103,7 +106,7 @@ class EntityMap {
[val], [val],
(err, rs) => { (err, rs) => {
if (err) { if (err) {
console.log(err); logger.log(err);
reject(err); reject(err);
} }
if (rs) { if (rs) {
@ -122,7 +125,7 @@ class EntityMap {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.db.get(`SELECT COUNT(*) as count FROM mapping`, (err, rs) => { this.db.get(`SELECT COUNT(*) as count FROM mapping`, (err, rs) => {
if (err) { if (err) {
console.log(err); logger.log(err);
reject(err); reject(err);
} }
resolve(rs.count); resolve(rs.count);
@ -153,7 +156,7 @@ class EntityMap {
} FROM mapping LIMIT ${limit} OFFSET ${offset}`, } FROM mapping LIMIT ${limit} OFFSET ${offset}`,
(err, rs) => { (err, rs) => {
if (err) { if (err) {
console.log(err); logger.log(err);
reject(err); reject(err);
} }
for (let row of rs) { for (let row of rs) {
@ -200,7 +203,7 @@ function processResponseRow(res: any) {
try { try {
res[key] = JSON.parse(res[key].replace('JSON::', '')); res[key] = JSON.parse(res[key].replace('JSON::', ''));
} catch (e) { } catch (e) {
console.log(e); logger.log(e);
} }
} }
if (revertKey(key) !== key) { 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'; import axios from 'axios';
const logger = new Logger('FetchAT');
const info: any = { const info: any = {
initialized: false, initialized: false,
}; };
@ -44,7 +47,7 @@ async function initialize(shareId, appId?: string) {
return response.data; return response.data;
}) })
.catch((e) => { .catch((e) => {
console.log(e); logger.log(e);
throw { throw {
message: message:
'Invalid Shared Base ID :: Ensure www.airtable.com/<SharedBaseID> is accessible. Refer https://bit.ly/3x0OdXI for details', '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.baseId = info.baseInfo.applicationId;
info.initialized = true; info.initialized = true;
} catch (e) { } catch (e) {
console.log(e); logger.log(e);
info.initialized = false; info.initialized = false;
if (e.message) { if (e.message) {
throw e; throw e;
@ -135,7 +138,7 @@ async function read() {
return response.data; return response.data;
}) })
.catch((e) => { .catch((e) => {
console.log(e); logger.log(e);
throw { throw {
message: message:
'Error Reading :: Ensure www.airtable.com/<SharedBaseID> is accessible. Refer https://bit.ly/3x0OdXI for details', '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; return response.data;
}) })
.catch((e) => { .catch((e) => {
console.log(e); logger.log(e);
throw { throw {
message: message:
'Error Reading View :: Ensure www.airtable.com/<SharedBaseID> is accessible. Refer https://bit.ly/3x0OdXI for details', '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; return response.data;
}) })
.catch((e) => { .catch((e) => {
console.log(e); logger.log(e);
throw { throw {
message: message:
'Error Fetching :: Ensure www.airtable.com/templates/featured/<TemplateID> is accessible.', 'Error Fetching :: Ensure www.airtable.com/templates/featured/<TemplateID> is accessible.',

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

@ -5,7 +5,6 @@ import {
Processor, Processor,
} from '@nestjs/bull'; } from '@nestjs/bull';
import { Job } from 'bull'; import { Job } from 'bull';
import boxen from 'boxen';
import { EventEmitter2 } from '@nestjs/event-emitter'; import { EventEmitter2 } from '@nestjs/event-emitter';
import { Logger } from '@nestjs/common'; import { Logger } from '@nestjs/common';
import { JobEvents, JOBS_QUEUE, JobStatus } from '~/interface/Jobs'; import { JobEvents, JOBS_QUEUE, JobStatus } from '~/interface/Jobs';
@ -28,15 +27,8 @@ export class JobsEventService {
@OnQueueFailed() @OnQueueFailed()
onFailed(job: Job, error: Error) { onFailed(job: Job, error: Error) {
this.logger.error(`Job ${job.id} failed with error ${error.message}`); this.logger.error(`Job ${job.id} failed with error ${error.message}`);
console.error( this.logger.error(
boxen(
`---- !! JOB FAILED !! ----\nid:${job.id}\nerror:${error.name} (${error.message})\n\nstack: ${error.stack}`, `---- !! JOB FAILED !! ----\nid:${job.id}\nerror:${error.name} (${error.message})\n\nstack: ${error.stack}`,
{
padding: 1,
borderStyle: 'double',
borderColor: 'yellow',
},
),
); );
this.eventEmitter.emit(JobEvents.STATUS, { 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 Redis from 'ioredis';
import { InstanceTypes } from '~/interface/Jobs'; import { InstanceTypes } from '~/interface/Jobs';
@Injectable() @Injectable()
export class JobsRedisService { export class JobsRedisService {
protected logger = new Logger(JobsRedisService.name);
private redisClient: Redis; private redisClient: Redis;
private redisSubscriber: Redis; private redisSubscriber: Redis;
private unsubscribeCallbacks: { [key: string]: () => void } = {}; private unsubscribeCallbacks: { [key: string]: () => void } = {};
@ -42,7 +44,7 @@ export class JobsRedisService {
try { try {
this.redisClient.publish(channel, JSON.stringify(message)); this.redisClient.publish(channel, JSON.stringify(message));
} catch (e) { } catch (e) {
console.error(e); this.logger.error(e);
} }
} }
} }

Loading…
Cancel
Save