Promise has sequenced import tasks in .gbkb.
This commit is contained in:
parent
88c190254d
commit
8ca77a4a63
1 changed files with 102 additions and 110 deletions
|
@ -359,17 +359,14 @@ export class KBService {
|
||||||
instanceId: number,
|
instanceId: number,
|
||||||
packageId: number
|
packageId: number
|
||||||
): Promise<GuaribasQuestion[]> {
|
): Promise<GuaribasQuestion[]> {
|
||||||
return new Promise<GuaribasQuestion[]>(
|
|
||||||
(resolve, reject) => {
|
|
||||||
|
|
||||||
let file = Fs.readFileSync(filePath, "UCS-2")
|
let file = Fs.readFileSync(filePath, "UCS-2")
|
||||||
let opts = {
|
let opts = {
|
||||||
delimiter: "\t"
|
delimiter: "\t"
|
||||||
}
|
}
|
||||||
|
|
||||||
parse(file, opts).then((data) => {
|
let data = await parse(file, opts);
|
||||||
return asyncPromise.eachSeries(data, line => {
|
return asyncPromise.eachSeries(data, async line => {
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
|
|
||||||
// Extracts values from columns in the current line.
|
// Extracts values from columns in the current line.
|
||||||
|
|
||||||
|
@ -420,13 +417,13 @@ export class KBService {
|
||||||
|
|
||||||
// Now with all the data ready, creates entities in the store.
|
// Now with all the data ready, creates entities in the store.
|
||||||
|
|
||||||
GuaribasAnswer.create({
|
let answer1 = await GuaribasAnswer.create({
|
||||||
instanceId: instanceId,
|
instanceId: instanceId,
|
||||||
content: answer,
|
content: answer,
|
||||||
format: format,
|
format: format,
|
||||||
packageId: packageId
|
packageId: packageId
|
||||||
}).then((answer: GuaribasAnswer) => {
|
});
|
||||||
return GuaribasQuestion.create({
|
await GuaribasQuestion.create({
|
||||||
from: from,
|
from: from,
|
||||||
to: to,
|
to: to,
|
||||||
subject1: subject1,
|
subject1: subject1,
|
||||||
|
@ -435,23 +432,19 @@ export class KBService {
|
||||||
subject4: subject4,
|
subject4: subject4,
|
||||||
content: question,
|
content: question,
|
||||||
instanceId: instanceId,
|
instanceId: instanceId,
|
||||||
answerId: answer.answerId,
|
answerId: answer1.answerId,
|
||||||
packageId: packageId
|
packageId: packageId
|
||||||
}).then((question: GuaribasQuestion) => {
|
});
|
||||||
resolve(question)
|
logger.info(`Question created: ${question.questionId}`)
|
||||||
}).error(reason => reject(reason))
|
return Promise.resolve(question)
|
||||||
}).error(reason => reject(reason))
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
let msg = `[GBImporter] Missing header in file: ${filePath}`;
|
|
||||||
logger.info(msg)
|
|
||||||
resolve(null)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}).error(reason => reject(reason))
|
|
||||||
|
|
||||||
resolve(null)
|
// Skips the header.
|
||||||
|
|
||||||
|
return Promise.resolve(null)
|
||||||
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -540,17 +533,14 @@ export class KBService {
|
||||||
packageId: number,
|
packageId: number,
|
||||||
filename: string,
|
filename: string,
|
||||||
instance: IGBInstance
|
instance: IGBInstance
|
||||||
): Promise<GuaribasQuestion[]> {
|
): Promise<any> {
|
||||||
return new Promise<GuaribasQuestion[]>(
|
|
||||||
(resolve, reject) => {
|
|
||||||
|
|
||||||
var subjects = JSON.parse(Fs.readFileSync(filename, "utf8"))
|
var subjects = JSON.parse(Fs.readFileSync(filename, "utf8"))
|
||||||
|
|
||||||
const doIt = (subjects: GuaribasSubject[], parentSubjectId: number) =>
|
const doIt = async (subjects: GuaribasSubject[], parentSubjectId: number) => {
|
||||||
new Promise((resolve, reject) => {
|
return asyncPromise.eachSeries(subjects, async item => {
|
||||||
asyncPromise.eachSeries(subjects, item => {
|
|
||||||
let mediaFilename = item.id + ".png"
|
let mediaFilename = item.id + ".png"
|
||||||
GuaribasSubject.create({
|
|
||||||
|
let value = await GuaribasSubject.create({
|
||||||
internalId: item.id,
|
internalId: item.id,
|
||||||
parentSubjectId: parentSubjectId,
|
parentSubjectId: parentSubjectId,
|
||||||
instanceId: instance.instanceId,
|
instanceId: instance.instanceId,
|
||||||
|
@ -559,19 +549,21 @@ export class KBService {
|
||||||
title: item.title,
|
title: item.title,
|
||||||
description: item.description,
|
description: item.description,
|
||||||
packageId: packageId
|
packageId: packageId
|
||||||
}).then((value: any) => {
|
});
|
||||||
if (item.children) {
|
|
||||||
doIt(item.children, value.subjectId)
|
if (item.children) {
|
||||||
}
|
return Promise.resolve(doIt(item.children, value.subjectId))
|
||||||
})
|
}
|
||||||
})
|
else {
|
||||||
})
|
return Promise.resolve(item);
|
||||||
|
}
|
||||||
|
|
||||||
doIt(subjects.children, null)
|
|
||||||
resolve()
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return doIt(subjects.children, null)
|
||||||
|
}
|
||||||
|
|
||||||
undeployKbFromStorage(
|
undeployKbFromStorage(
|
||||||
instance: IGBInstance,
|
instance: IGBInstance,
|
||||||
packageId: number
|
packageId: number
|
||||||
|
@ -607,7 +599,7 @@ export class KBService {
|
||||||
async deployKb(core: IGBCoreService, deployer: GBDeployer, localPath: string) {
|
async deployKb(core: IGBCoreService, deployer: GBDeployer, localPath: string) {
|
||||||
let packageType = Path.extname(localPath)
|
let packageType = Path.extname(localPath)
|
||||||
let packageName = Path.basename(localPath)
|
let packageName = Path.basename(localPath)
|
||||||
logger.info("[GBDeployer] Opening package: ", packageName)
|
logger.info("[GBDeployer] Opening package: ", localPath)
|
||||||
let packageObject = JSON.parse(
|
let packageObject = JSON.parse(
|
||||||
Fs.readFileSync(UrlJoin(localPath, "package.json"), "utf8")
|
Fs.readFileSync(UrlJoin(localPath, "package.json"), "utf8")
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Reference in a new issue