fix(basic.gblib): Allow MERGE keyword in storage #380. @othonlima
This commit is contained in:
parent
d79221a7ff
commit
4ff3cbafd5
2 changed files with 38 additions and 12 deletions
|
@ -653,6 +653,28 @@ export class SystemKeywords {
|
||||||
await this.save({ pid, file: "Notes.xlsx", args: [text] });
|
await this.save({ pid, file: "Notes.xlsx", args: [text] });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Saves variables to storage, not a worksheet.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public async saveToStorageBatch({ pid, table, rows }): Promise<void> {
|
||||||
|
const { min } = await DialogKeywords.getProcessInfo(pid);
|
||||||
|
GBLog.info(`BASIC: Saving to storage '${table}' (SAVE).`);
|
||||||
|
|
||||||
|
const definition = this.getTableFromName(table, min);
|
||||||
|
|
||||||
|
await retry(
|
||||||
|
async (bail) => {
|
||||||
|
await definition.bulkCreate(rows);
|
||||||
|
},
|
||||||
|
{
|
||||||
|
retries: 5,
|
||||||
|
onRetry: (err) => { GBLog.error(`Retrying SaveToStorageBatch due to: ${err.message}.`); }
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves variables to storage, not a worksheet.
|
* Saves variables to storage, not a worksheet.
|
||||||
*
|
*
|
||||||
|
@ -683,7 +705,7 @@ export class SystemKeywords {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
retries: 5,
|
retries: 5,
|
||||||
onRetry: (err) => { GBLog.error(`Retrying due to: ${err.message}.`); }
|
onRetry: (err) => { GBLog.error(`Retrying SaveToStorage due to: ${err.message}.`); }
|
||||||
}
|
}
|
||||||
|
|
||||||
);
|
);
|
||||||
|
@ -1644,6 +1666,7 @@ export class SystemKeywords {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
retries: 5,
|
retries: 5,
|
||||||
|
onRetry: (err) => { GBLog.error(`Retrying HTTP GET due to: ${err.message}.`); }
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
let res = JSON.parse(await result.text());
|
let res = JSON.parse(await result.text());
|
||||||
|
@ -2013,6 +2036,7 @@ export class SystemKeywords {
|
||||||
let t;
|
let t;
|
||||||
let fieldsNames = [];
|
let fieldsNames = [];
|
||||||
let fieldsSizes = [];
|
let fieldsSizes = [];
|
||||||
|
let fieldsValuesList = [];
|
||||||
|
|
||||||
if (storage) {
|
if (storage) {
|
||||||
|
|
||||||
|
@ -2030,19 +2054,14 @@ export class SystemKeywords {
|
||||||
fieldsSizes.push(t.fieldRawAttributesMap[e].size);
|
fieldsSizes.push(t.fieldRawAttributesMap[e].size);
|
||||||
})
|
})
|
||||||
|
|
||||||
|
header = Object.keys(t.fieldRawAttributesMap);
|
||||||
if (!this.cachedMerge[pid][file]) {
|
if (!this.cachedMerge[pid][file]) {
|
||||||
rows = await t.findAll({});
|
rows = await t.findAll({});
|
||||||
header = Object.keys(rows[0].dataValues)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
rows = this.cachedMerge[pid][file];
|
rows = this.cachedMerge[pid][file];
|
||||||
|
|
||||||
header = Object.keys(rows[0])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rows.length > 0) {
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
const botId = min.instance.botId;
|
const botId = min.instance.botId;
|
||||||
|
@ -2232,6 +2251,7 @@ export class SystemKeywords {
|
||||||
let dst = {};
|
let dst = {};
|
||||||
|
|
||||||
// Uppercases fields.
|
// Uppercases fields.
|
||||||
|
|
||||||
let i = 0;
|
let i = 0;
|
||||||
Object.keys(fieldsValues).forEach(fieldSrc => {
|
Object.keys(fieldsValues).forEach(fieldSrc => {
|
||||||
const field = fieldsNames[i].charAt(0).toUpperCase() + fieldsNames[i].slice(1);
|
const field = fieldsNames[i].charAt(0).toUpperCase() + fieldsNames[i].slice(1);
|
||||||
|
@ -2241,7 +2261,7 @@ export class SystemKeywords {
|
||||||
i++;
|
i++;
|
||||||
});
|
});
|
||||||
|
|
||||||
await this.saveToStorage({ pid, table: file, fieldsValues, fieldsNames });
|
fieldsValuesList.push(dst);
|
||||||
this.cachedMerge[pid][file].push(dst);
|
this.cachedMerge[pid][file].push(dst);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -2252,6 +2272,12 @@ export class SystemKeywords {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// In case of storage, persist to DB in batch.
|
||||||
|
|
||||||
|
if (fieldsValuesList.length){
|
||||||
|
await this.saveToStorageBatch({ pid, table: file, rows:fieldsValuesList });
|
||||||
|
}
|
||||||
|
|
||||||
GBLog.info(`BASIC: MERGE updated (merges:${merges}, additions:${adds}, skipped: ${skipped}).`);
|
GBLog.info(`BASIC: MERGE updated (merges:${merges}, additions:${adds}, skipped: ${skipped}).`);
|
||||||
return table;
|
return table;
|
||||||
}
|
}
|
||||||
|
|
|
@ -160,11 +160,11 @@ export class GBServer {
|
||||||
} else {
|
} else {
|
||||||
GBServer.globals.publicAddress = await core.ensureProxy(port);
|
GBServer.globals.publicAddress = await core.ensureProxy(port);
|
||||||
process.env.BOT_URL = GBServer.globals.publicAddress;
|
process.env.BOT_URL = GBServer.globals.publicAddress;
|
||||||
GBLog.info(`Auto local proxy address defined at: ${process.env.BOT_URL}...`);
|
GBLog.info(`Auto-proxy address at: ${process.env.BOT_URL}...`);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const serverAddress = process.env.BOT_URL;
|
const serverAddress = process.env.BOT_URL;
|
||||||
GBLog.info(`Defining server address at ${serverAddress}...`);
|
GBLog.info(`.env address at ${serverAddress}...`);
|
||||||
GBServer.globals.publicAddress = serverAddress;
|
GBServer.globals.publicAddress = serverAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue