Получение списка сервисов и запись в журнал работы сервиса приложений ПП Парус 8

This commit is contained in:
Mikhail Chechnev 2018-11-08 21:28:33 +03:00
parent 70efa0250d
commit 158f276989
3 changed files with 98 additions and 29 deletions

View File

@ -90,7 +90,7 @@ class DBConnector {
throw new ServerError(glConst.ERR_DB_DISCONNECT, e.message); throw new ServerError(glConst.ERR_DB_DISCONNECT, e.message);
} }
} }
//Исполнить запрос //Получить список сервисов
async getServices() { async getServices() {
try { try {
let res = await this.connector.getServices(this.connection); let res = await this.connector.getServices(this.connection);
@ -99,6 +99,15 @@ class DBConnector {
throw new ServerError(glConst.ERR_DB_EXECUTE, e.message); throw new ServerError(glConst.ERR_DB_EXECUTE, e.message);
} }
} }
//Запись в журнал работы
async putLog(msg, queueID) {
try {
let res = await this.connector.log(this.connection, msg, queueID);
return res;
} catch (e) {
throw new ServerError(glConst.ERR_DB_EXECUTE, e.message);
}
}
} }
//----------------- //-----------------

View File

@ -26,27 +26,37 @@ a.connect()
a.getServices() a.getServices()
.then(res => { .then(res => {
console.log(res); console.log(res);
setTimeout(() => { a.putLog("Сервер приложений подключен")
a.disconnect() .then(res => {
.then(res => { console.log(res);
console.log("DISCONNECTED"); a.disconnect()
}) .then(res => {
.catch(e => { console.log("DISCONNECTED");
console.log(e.code + ": " + e.message); })
}); .catch(e => {
}, 10000); console.log(e.code + ": " + e.message);
});
})
.catch(e => {
console.log(e.code + ": " + e.message);
a.disconnect()
.then(res => {
console.log("DISCONNECTED");
})
.catch(e => {
console.log(e.code + ": " + e.message);
});
});
}) })
.catch(e => { .catch(e => {
console.log(e.code + ": " + e.message); console.log(e.code + ": " + e.message);
setTimeout(() => { a.disconnect()
a.disconnect() .then(res => {
.then(res => { console.log("DISCONNECTED");
console.log("DISCONNECTED"); })
}) .catch(e => {
.catch(e => { console.log(e.code + ": " + e.message);
console.log(e.code + ": " + e.message); });
});
}, 10000);
}); });
}) })
.catch(e => { .catch(e => {

View File

@ -22,9 +22,9 @@ const connect = prms => {
password: prms.password, password: prms.password,
connectString: prms.connectString connectString: prms.connectString
}, },
function(err, connection) { (err, connection) => {
if (err) { if (err) {
reject(err); reject(new Error(err.message));
} else { } else {
resolve(connection); resolve(connection);
} }
@ -37,9 +37,9 @@ const connect = prms => {
const disconnect = connection => { const disconnect = connection => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (connection) { if (connection) {
connection.close(function(err) { connection.close(err => {
if (err) { if (err) {
reject(err); reject(new Error(err.message));
} else { } else {
resolve(); resolve();
} }
@ -54,12 +54,28 @@ const disconnect = connection => {
const getServices = connection => { const getServices = connection => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (connection) { if (connection) {
connection.execute("select * from EXSSERVICE", [], { outFormat: oracledb.OBJECT }, (err, result) => { connection.execute(
if (err) { "BEGIN PKG_EXS.SERVICE_GET(RCSERVICES => :RCSERVICES); END;",
reject(err); { RCSERVICES: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT } },
{ outFormat: oracledb.OBJECT },
(err, result) => {
if (err) {
reject(new Error(err.message));
}
let cursor = result.outBinds.RCSERVICES;
let queryStream = cursor.toQueryStream();
let rows = [];
queryStream.on("data", row => {
rows.push(row);
});
queryStream.on("error", err => {
reject(new Error(err.message));
});
queryStream.on("close", () => {
resolve(rows);
});
} }
resolve(result.rows); );
});
} else { } else {
reject(new Error("Не указано подключение")); reject(new Error("Не указано подключение"));
} }
@ -67,7 +83,41 @@ const getServices = connection => {
}; };
//Запись в протокол работы //Запись в протокол работы
const log = prms => {}; const log = (connection, msg, queueID) => {
return new Promise((resolve, reject) => {
if (connection) {
connection.execute(
"BEGIN PKG_EXS.LOG_PUT(NLOG_STATE => :NLOG_STATE, SMSG => :SMSG, NEXSQUEUE => :NEXSQUEUE, RCLOG => :RCLOG); END;",
{
NLOG_STATE: 0,
SMSG: msg,
NEXSQUEUE: queueID,
RCLOG: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
},
{ outFormat: oracledb.OBJECT, autoCommit: true },
(err, result) => {
if (err) {
reject(new Error(err.message));
}
let cursor = result.outBinds.RCLOG;
let queryStream = cursor.toQueryStream();
let rows = [];
queryStream.on("data", row => {
rows.push(row);
});
queryStream.on("error", err => {
reject(new Error(err.message));
});
queryStream.on("close", () => {
resolve(rows[0]);
});
}
);
} else {
reject(new Error("Не указано подключение"));
}
});
};
//Считывание очередной порции исходящих сообщений из очереди //Считывание очередной порции исходящих сообщений из очереди
const getQueueOutgoing = prms => {}; const getQueueOutgoing = prms => {};