bulltrackers-module 1.0.227 → 1.0.228
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.
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* FILENAME: computation-system/helpers/computation_worker.js
|
|
3
3
|
* PURPOSE: Consumes computation tasks from Pub/Sub and executes them.
|
|
4
|
-
* UPDATED:
|
|
4
|
+
* UPDATED: Instantiates the internal StructuredLogger to replace the generic injected logger.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
const { runDateComputation, groupByPass } = require('../WorkflowOrchestrator.js');
|
|
8
8
|
const { getManifest } = require('../topology/ManifestLoader');
|
|
9
|
+
const { StructuredLogger } = require('../logger/logger'); // <--- CRITICAL IMPORT
|
|
9
10
|
|
|
10
|
-
// 1. IMPORT CALCULATIONS
|
|
11
|
+
// 1. IMPORT CALCULATIONS
|
|
11
12
|
// We import the specific package containing your strategies (gem, pyro, core, etc.)
|
|
12
|
-
// Adjust the require path if you are using a local relative path instead of node_modules.
|
|
13
13
|
let calculationPackage;
|
|
14
14
|
try {
|
|
15
15
|
// Primary: Try to load from the installed npm package
|
|
@@ -21,34 +21,50 @@ try {
|
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
// The package exports { calculations: { ... }, utils: { ... } }
|
|
24
|
-
// We only need the 'calculations' object (which contains the folder-grouped classes)
|
|
25
24
|
const calculations = calculationPackage.calculations;
|
|
26
25
|
|
|
27
26
|
/**
|
|
28
27
|
* Handles a single Pub/Sub message for a computation task.
|
|
29
28
|
* Supports both Gen 1 (Message) and Gen 2 (CloudEvent) formats.
|
|
30
29
|
* @param {object} message - The Pub/Sub message payload.
|
|
31
|
-
* @param {object} config - System configuration
|
|
32
|
-
* @param {object} dependencies -
|
|
30
|
+
* @param {object} config - System configuration.
|
|
31
|
+
* @param {object} dependencies - Injected dependencies (db, generic logger, etc.).
|
|
33
32
|
*/
|
|
34
33
|
async function handleComputationTask(message, config, dependencies) {
|
|
35
|
-
|
|
34
|
+
|
|
35
|
+
// 2. INITIALIZE SYSTEM LOGGER
|
|
36
|
+
// We ignore the generic 'dependencies.logger' and instantiate our specialized one.
|
|
37
|
+
// This ensures methods like 'logDateAnalysis' and 'logStorage' exist.
|
|
38
|
+
const systemLogger = new StructuredLogger({
|
|
39
|
+
minLevel: config.minLevel || 'INFO',
|
|
40
|
+
enableStructured: true,
|
|
41
|
+
...config // Apply any other relevant config overrides
|
|
42
|
+
});
|
|
36
43
|
|
|
37
|
-
//
|
|
38
|
-
// We
|
|
44
|
+
// 3. OVERRIDE DEPENDENCIES
|
|
45
|
+
// We create a new dependencies object to pass downstream.
|
|
46
|
+
// This fixes the "logger.logStorage is not a function" error in ResultCommitter.js
|
|
47
|
+
const runDependencies = {
|
|
48
|
+
...dependencies,
|
|
49
|
+
logger: systemLogger
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const { logger } = runDependencies; // Use this for local logging
|
|
53
|
+
|
|
54
|
+
// 4. LAZY LOAD MANIFEST
|
|
39
55
|
let computationManifest;
|
|
40
56
|
try {
|
|
41
57
|
computationManifest = getManifest(
|
|
42
58
|
config.activeProductLines || [],
|
|
43
59
|
calculations,
|
|
44
|
-
dependencies
|
|
60
|
+
runDependencies // Pass the updated dependencies
|
|
45
61
|
);
|
|
46
62
|
} catch (manifestError) {
|
|
47
63
|
logger.log('FATAL', `[Worker] Failed to load Manifest: ${manifestError.message}`);
|
|
48
64
|
return;
|
|
49
65
|
}
|
|
50
66
|
|
|
51
|
-
//
|
|
67
|
+
// 5. PARSE PUB/SUB MESSAGE
|
|
52
68
|
let data;
|
|
53
69
|
try {
|
|
54
70
|
if (message.data && message.data.message && message.data.message.data) {
|
|
@@ -67,7 +83,7 @@ async function handleComputationTask(message, config, dependencies) {
|
|
|
67
83
|
return;
|
|
68
84
|
}
|
|
69
85
|
|
|
70
|
-
//
|
|
86
|
+
// 6. EXECUTE TASK
|
|
71
87
|
try {
|
|
72
88
|
if (!data || data.action !== 'RUN_COMPUTATION_DATE') {
|
|
73
89
|
if (data) logger.log('WARN', `[Worker] Unknown or missing action: ${data?.action}. Ignoring.`);
|
|
@@ -95,7 +111,7 @@ async function handleComputationTask(message, config, dependencies) {
|
|
|
95
111
|
pass,
|
|
96
112
|
calcsInThisPass,
|
|
97
113
|
config,
|
|
98
|
-
|
|
114
|
+
runDependencies, // <--- IMPORTANT: Pass the dependencies with the System Logger
|
|
99
115
|
computationManifest
|
|
100
116
|
);
|
|
101
117
|
|