@openinc/parse-server-opendash 4.0.22 → 4.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hooks/MES_Order.js +39 -43
- package/package.json +1 -1
package/dist/hooks/MES_Order.js
CHANGED
|
@@ -43,6 +43,8 @@ const cron_1 = require("cron");
|
|
|
43
43
|
const index_js_1 = require("../features/openware/index.js");
|
|
44
44
|
const index_js_2 = require("../features/schema/index.js");
|
|
45
45
|
const index_js_3 = require("../types/index.js");
|
|
46
|
+
// Tolerance for client/server clock skew when comparing `start` against `now`.
|
|
47
|
+
const CLOCK_SKEW_MS = 60_000;
|
|
46
48
|
const excludeFields = [
|
|
47
49
|
"ACL",
|
|
48
50
|
"updatedAt",
|
|
@@ -80,8 +82,6 @@ async function init() {
|
|
|
80
82
|
const { object, original, user } = request;
|
|
81
83
|
if (!object.id)
|
|
82
84
|
return;
|
|
83
|
-
// Non-sync client & Server times. ALlow 1 minute difference
|
|
84
|
-
const nowThresholded = Date.now() - 60_000;
|
|
85
85
|
await (0, index_js_2.defaultHandler)(request);
|
|
86
86
|
await (0, index_js_2.defaultAclHandler)(request, {
|
|
87
87
|
allowCustomACL: true,
|
|
@@ -106,27 +106,27 @@ async function init() {
|
|
|
106
106
|
: article?.get("targettime") || 0);
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
|
-
//
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
109
|
+
// Re-evaluate status. Terminal states (done/canceled) are preserved; any
|
|
110
|
+
// other status — including "unknown" — is recomputed so orders can heal
|
|
111
|
+
// when source/tag arrive on a later save. Clock skew is tolerated in both
|
|
112
|
+
// directions: starts up to CLOCK_SKEW_MS in the future count as "started",
|
|
113
|
+
// and a missing source only produces "unknown" once `start` has clearly
|
|
114
|
+
// passed.
|
|
115
|
+
const currentStatus = object.get("status");
|
|
116
|
+
const start = object.get("start");
|
|
117
|
+
const hasSource = !!object.get("source");
|
|
118
|
+
if (currentStatus !== "done" && currentStatus !== "canceled" && start) {
|
|
119
|
+
const startMs = start.getTime();
|
|
120
|
+
const nowMs = Date.now();
|
|
121
|
+
if (hasSource) {
|
|
122
|
+
object.set("status", startMs < nowMs + CLOCK_SKEW_MS ? "running" : "planned");
|
|
123
|
+
}
|
|
124
|
+
else if (startMs < nowMs - CLOCK_SKEW_MS) {
|
|
125
|
+
object.set("status", "unknown");
|
|
126
|
+
}
|
|
127
127
|
}
|
|
128
128
|
// If the order has been started and ended, it is done
|
|
129
|
-
if (
|
|
129
|
+
if (start &&
|
|
130
130
|
object.get("duration") &&
|
|
131
131
|
(object.get("status") === "running" || object.get("status") === "planned")) {
|
|
132
132
|
object.set("status", "done");
|
|
@@ -315,29 +315,25 @@ function scheduleOrderStartedStatusCheck(cronInterval) {
|
|
|
315
315
|
query.find({ useMasterKey: true }).then((orders) => {
|
|
316
316
|
orders.forEach((order) => {
|
|
317
317
|
const status = order.get("status");
|
|
318
|
-
if (
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
318
|
+
if (status === "done" || status === "canceled")
|
|
319
|
+
return;
|
|
320
|
+
const startMs = order.get("start").getTime();
|
|
321
|
+
const nowMs = Date.now();
|
|
322
|
+
const hasStarted = startMs < nowMs + CLOCK_SKEW_MS;
|
|
323
|
+
const hasTag = !!order.get("tag");
|
|
324
|
+
let next;
|
|
325
|
+
if (hasTag) {
|
|
326
|
+
next = hasStarted ? "running" : "planned";
|
|
327
|
+
}
|
|
328
|
+
else if (startMs < nowMs - CLOCK_SKEW_MS) {
|
|
329
|
+
next = "unknown";
|
|
330
|
+
}
|
|
331
|
+
else if (!status) {
|
|
332
|
+
next = "planned";
|
|
333
333
|
}
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
order.set("status", "running");
|
|
338
|
-
order.save(null, { useMasterKey: true });
|
|
339
|
-
}
|
|
340
|
-
}
|
|
334
|
+
if (next && next !== status) {
|
|
335
|
+
order.set("status", next);
|
|
336
|
+
order.save(null, { useMasterKey: true });
|
|
341
337
|
}
|
|
342
338
|
});
|
|
343
339
|
});
|