Skip to content

Commit

Permalink
feat(pusher): collect import logs for debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
hungluu committed Feb 2, 2024
1 parent 77dfa02 commit f1d7498
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
19 changes: 18 additions & 1 deletion src/modules/mover/MoverServerOutlinePusher.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { pathExists } from 'fs-extra'
import { ensureDir, pathExists, writeJson } from 'fs-extra'
import { SERVER_IMPORT_ISSUES, SERVER_IMPORT_LOGS, STATUS_IMPORT_CONFIRMING, STATUS_IMPORT_DONE, STATUS_IMPORT_PROCESSING, STATUS_IMPORT_VALIDATING } from './events'
import type {
ICodaDoc,
Expand All @@ -10,8 +10,11 @@ import type {
IOutlineApis,
IPusher,
} from './interfaces'
import { importsPath } from './paths'
import { TaskPriority } from '@abxvn/tasks'

export class MoverServerOutlinePusher implements IPusher {
static readonly CONNECTOR_ID = 'outline'
private _processedInstructionCount = 0

constructor (
Expand Down Expand Up @@ -107,6 +110,15 @@ export class MoverServerOutlinePusher implements IPusher {
await this.processInstruction(instruction)
})
})

const processTimestamp = new Date().toISOString().slice(0, 19).replace(/:/g, '')

// save import data for debugging
this.server.queue(
'save import data',
async () => await this.saveData(`${MoverServerOutlinePusher.CONNECTOR_ID}-${processTimestamp}.json`),
TaskPriority.IDLE,
)
}

private async processInstruction (instruction: IImportInstruction) {
Expand Down Expand Up @@ -197,6 +209,11 @@ export class MoverServerOutlinePusher implements IPusher {
this.server.emit(SERVER_IMPORT_LOGS, logs)
}

async saveData (jsonFileName: string) {
await ensureDir(importsPath)
await writeJson(`${importsPath}/${jsonFileName}`, this.data)
}

private addInstruction (instruction: Omit<IImportInstruction, 'id'>) {
this.data.instructions.push({
id: this.data.instructions.length,
Expand Down
8 changes: 1 addition & 7 deletions src/modules/mover/MoverServerPuller.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import { createWriteStream, ensureDir, pathExists, readJson, rename, writeJson } from 'fs-extra'
import { CLIENT_SYNC_DOCS, SERVER_RETURN_DOCS, SERVER_RETURN_PAGES } from './events'
import type { ICodaApiDoc, ICodaApiPage, ICodaDoc, ICodaItem, ICodaPage, IPuller, ICodaItems, IMoverServer } from './interfaces'
import { resolve } from 'path'
import { TaskPriority } from '@abxvn/tasks'
import type { ICodaApis } from './apis/interfaces'
import { download } from './apis'

const rootPath = resolve(__dirname, '../../../../').replace(/\\/g, '/') // fix path separator for windows
const dataPath = `${rootPath}/data`
const codaJsonPath = `${dataPath}/coda.json`
const codaDocsPath = `${dataPath}/docs`
import { codaDocsPath, codaJsonPath } from './paths'

export class MoverServerPuller implements IPuller {
private _exportingCount = 0
Expand Down Expand Up @@ -260,7 +255,6 @@ export class MoverServerPuller implements IPuller {
}

async saveData () {
await ensureDir(dataPath)
await writeJson(codaJsonPath, Object.values(this.items))
}

Expand Down
10 changes: 10 additions & 0 deletions src/modules/mover/paths.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { resolve } from 'path'

export const rootPath = resolve(__dirname, '../../../../')
.replace(/\\/g, '/') // fix path separator for windows
export const dataPath = `${rootPath}/data`

export const codaDocsPath = `${dataPath}/docs`
export const codaJsonPath = `${dataPath}/coda.json`

export const importsPath = `${dataPath}/imports`

0 comments on commit f1d7498

Please sign in to comment.