mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 08:27:08 +00:00
Use DEBUG library throughout
This commit is contained in:
@@ -1,23 +1,24 @@
|
|||||||
const { schema2pid } = require('../../lib/db/connection');
|
const { schema2pid } = require('../../lib/db/connection');
|
||||||
const { event } = require('../../lib/db');
|
const { event } = require('../../lib/db');
|
||||||
|
const { ALERT, ERROR, WARNING, NOTICE, INFO, DEBUG } = require('DOUGAL_ROOT/debug')(__filename);
|
||||||
|
|
||||||
class DetectSOLEOL {
|
class DetectSOLEOL {
|
||||||
/* Data may come much faster than we can process it, so we put it
|
/* Data may come much faster than we can process it, so we put it
|
||||||
* in a queue and process it at our own pace.
|
* in a queue and process it at our own pace.
|
||||||
*
|
*
|
||||||
* The run() method fills the queue with the necessary data and then
|
* The run() method fills the queue with the necessary data and then
|
||||||
* calls processQueue().
|
* calls processQueue().
|
||||||
*
|
*
|
||||||
* The processQueue() method looks takes the first two elements in
|
* The processQueue() method looks takes the first two elements in
|
||||||
* the queue and processes them if they are not already being taken
|
* the queue and processes them if they are not already being taken
|
||||||
* care of by a previous processQueue() call – this will happen when
|
* care of by a previous processQueue() call – this will happen when
|
||||||
* data is coming in faster than it can be processed.
|
* data is coming in faster than it can be processed.
|
||||||
*
|
*
|
||||||
* If the processQueue() call is the first to see the two bottommost
|
* If the processQueue() call is the first to see the two bottommost
|
||||||
* two elements, it will process them and, when finished, it will set
|
* two elements, it will process them and, when finished, it will set
|
||||||
* the `isPending` flag of the bottommost element to `false`, thus
|
* the `isPending` flag of the bottommost element to `false`, thus
|
||||||
* letting the next call know that it has work to do.
|
* letting the next call know that it has work to do.
|
||||||
*
|
*
|
||||||
* If the queue was empty, run() will set the `isPending` flag of its
|
* If the queue was empty, run() will set the `isPending` flag of its
|
||||||
* first element to a falsy value, thus bootstrapping the process.
|
* first element to a falsy value, thus bootstrapping the process.
|
||||||
*/
|
*/
|
||||||
@@ -26,8 +27,10 @@ class DetectSOLEOL {
|
|||||||
queue = [];
|
queue = [];
|
||||||
|
|
||||||
async processQueue () {
|
async processQueue () {
|
||||||
|
DEBUG("Queue length", this.queue.length)
|
||||||
while (this.queue.length > 1) {
|
while (this.queue.length > 1) {
|
||||||
if (this.queue[0].isPending) {
|
if (this.queue[0].isPending) {
|
||||||
|
DEBUG("Queue busy");
|
||||||
setImmediate(() => this.processQueue());
|
setImmediate(() => this.processQueue());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -38,9 +41,15 @@ class DetectSOLEOL {
|
|||||||
const sequence = Number(cur._sequence);
|
const sequence = Number(cur._sequence);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
DEBUG("Sequence", sequence);
|
||||||
|
// DEBUG("Previous", prev);
|
||||||
|
// DEBUG("Current", cur);
|
||||||
|
|
||||||
if (prev.lineName == cur.lineName && prev._sequence == cur._sequence &&
|
if (prev.lineName == cur.lineName && prev._sequence == cur._sequence &&
|
||||||
prev.lineStatus != "online" && cur.lineStatus == "online" && sequence) {
|
prev.lineStatus != "online" && cur.lineStatus == "online" && sequence) {
|
||||||
|
INFO("Transition to ONLINE detected");
|
||||||
|
// DEBUG(cur);
|
||||||
|
// DEBUG(prev);
|
||||||
// console.log("TRANSITION TO ONLINE", prev, cur);
|
// console.log("TRANSITION TO ONLINE", prev, cur);
|
||||||
|
|
||||||
// Check if there are already FSP, FGSP events for this sequence
|
// Check if there are already FSP, FGSP events for this sequence
|
||||||
@@ -63,12 +72,17 @@ class DetectSOLEOL {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// console.log(projectId, payload);
|
// console.log(projectId, payload);
|
||||||
|
INFO("Posting event", projectId, payload);
|
||||||
await event.post(projectId, payload);
|
await event.post(projectId, payload);
|
||||||
} else {
|
} else {
|
||||||
// A first shot point has been already entered in the log,
|
// A first shot point has been already entered in the log,
|
||||||
// so we have nothing to do here.
|
// so we have nothing to do here.
|
||||||
|
INFO("FSP already in the log. Doing nothing");
|
||||||
}
|
}
|
||||||
} else if (prev.lineStatus == "online" && cur.lineStatus != "online") {
|
} else if (prev.lineStatus == "online" && cur.lineStatus != "online") {
|
||||||
|
INFO("Transition to OFFLINE detected");
|
||||||
|
// DEBUG(cur);
|
||||||
|
// DEBUG(prev);
|
||||||
// console.log("TRANSITION TO OFFLINE", prev, cur);
|
// console.log("TRANSITION TO OFFLINE", prev, cur);
|
||||||
|
|
||||||
// Check if there are already LSP, LGSP events for this sequence
|
// Check if there are already LSP, LGSP events for this sequence
|
||||||
@@ -91,10 +105,12 @@ class DetectSOLEOL {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// console.log(projectId, payload);
|
// console.log(projectId, payload);
|
||||||
|
INFO("Posting event", projectId, payload);
|
||||||
await event.post(projectId, payload);
|
await event.post(projectId, payload);
|
||||||
} else {
|
} else {
|
||||||
// A first shot point has been already entered in the log,
|
// A first shot point has been already entered in the log,
|
||||||
// so we have nothing to do here.
|
// so we have nothing to do here.
|
||||||
|
INFO("LSP already in the log. Doing nothing");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Processing of this shot has already been completed.
|
// Processing of this shot has already been completed.
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// FIXME This code is in painful need of refactoring
|
// FIXME This code is in painful need of refactoring
|
||||||
|
|
||||||
const { DEBUG } = require("DOUGAL_ROOT/debug")(__filename);
|
const { ALERT, ERROR, WARNING, NOTICE, INFO, DEBUG } = require('DOUGAL_ROOT/debug')(__filename);
|
||||||
const { setSurvey, transaction, pool } = require('../connection');
|
const { setSurvey, transaction, pool } = require('../connection');
|
||||||
|
|
||||||
let last_tstamp = 0;
|
let last_tstamp = 0;
|
||||||
@@ -154,8 +154,8 @@ async function saveOnline (dataset, opts = {}) {
|
|||||||
}
|
}
|
||||||
await transaction.commit(client);
|
await transaction.commit(client);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("ONLINE DATA INSERT ERROR");
|
ERROR("ONLINE DATA INSERT ERROR");
|
||||||
console.error(error);
|
ERROR(error);
|
||||||
await transaction.rollback(client);
|
await transaction.rollback(client);
|
||||||
} finally {
|
} finally {
|
||||||
client.release();
|
client.release();
|
||||||
@@ -249,10 +249,12 @@ async function save (navData, opts = {}) {
|
|||||||
const hasLinePoint = ("lineName" in navData && "point" in navData);
|
const hasLinePoint = ("lineName" in navData && "point" in navData);
|
||||||
if (!(hasLinePoint || hasLatLon || hasEastNorth)) {
|
if (!(hasLinePoint || hasLatLon || hasEastNorth)) {
|
||||||
// This is of no interest to us
|
// This is of no interest to us
|
||||||
console.warning("Ignoring data without useful values", navData);
|
NOTICE("Ignoring data without useful values", navData);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DEBUG("navData", navData);
|
||||||
|
|
||||||
if (navData.online === true) {
|
if (navData.online === true) {
|
||||||
|
|
||||||
// So we have a lineName, see which projects match the line pattern.
|
// So we have a lineName, see which projects match the line pattern.
|
||||||
@@ -261,7 +263,7 @@ async function save (navData, opts = {}) {
|
|||||||
|
|
||||||
if (candidates.length == 0) {
|
if (candidates.length == 0) {
|
||||||
// This is probably a test line, so we treat it as offline
|
// This is probably a test line, so we treat it as offline
|
||||||
console.log("No match");
|
WARNING("No match");
|
||||||
} else {
|
} else {
|
||||||
if (candidates.length == 1) {
|
if (candidates.length == 1) {
|
||||||
// Only one candidate, associate with it
|
// Only one candidate, associate with it
|
||||||
@@ -277,7 +279,7 @@ async function save (navData, opts = {}) {
|
|||||||
await saveOnline(candidates.filter(c => c.schema == destinationSchema), opts);
|
await saveOnline(candidates.filter(c => c.schema == destinationSchema), opts);
|
||||||
navData.payload._schema = destinationSchema;
|
navData.payload._schema = destinationSchema;
|
||||||
} else {
|
} else {
|
||||||
console.log("Nowhere to save to");
|
WARNING("Nowhere to save to");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user