bulltrackers-module 1.0.42 → 1.0.44
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.
|
@@ -44,34 +44,39 @@ async function getLatestNormalUserPortfolios(normalUserCollectionName, snapshots
|
|
|
44
44
|
return allPortfolios;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
const { FieldValue } = require('@google-cloud/firestore'); // Ensure FieldValue is imported
|
|
47
48
|
|
|
48
49
|
/**
|
|
49
|
-
* Resets the
|
|
50
|
+
* Resets the proxy locks map in the performance document.
|
|
50
51
|
* @async
|
|
51
|
-
* @param {string}
|
|
52
|
+
* @param {string} proxyPerformanceDocPath - e.g., 'system_state/proxy_performance'.
|
|
52
53
|
* @returns {Promise<void>}
|
|
53
54
|
*/
|
|
54
|
-
async function resetProxyLocks(
|
|
55
|
+
async function resetProxyLocks(proxyPerformanceDocPath) {
|
|
55
56
|
logger.log('INFO','[Core Utils] Resetting proxy locks...');
|
|
56
57
|
try {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if (snapshot.empty) {
|
|
61
|
-
logger.log('INFO','[Core Utils] No proxies found in a locked state.');
|
|
58
|
+
if (!proxyPerformanceDocPath) {
|
|
59
|
+
logger.log('ERROR', '[Core Utils] Missing proxyPerformanceDocPath. Cannot reset locks.');
|
|
62
60
|
return;
|
|
63
61
|
}
|
|
62
|
+
|
|
63
|
+
const perfDocRef = db.doc(proxyPerformanceDocPath);
|
|
64
64
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
// Atomically delete the 'locks' map.
|
|
66
|
+
// This instantly unlocks all proxies for the IntelligentProxyManager.
|
|
67
|
+
await perfDocRef.update({
|
|
68
|
+
locks: FieldValue.delete()
|
|
68
69
|
});
|
|
69
70
|
|
|
70
|
-
|
|
71
|
-
logger.log('INFO',`[Core Utils] Proxy locks reset for ${snapshot.size} proxies.`);
|
|
71
|
+
logger.log('INFO',`[Core Utils] Proxy locks map reset in ${proxyPerformanceDocPath}.`);
|
|
72
72
|
} catch (error) {
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
// Log an error if the document or field doesn't exist, but don't fail the orchestrator
|
|
74
|
+
if (error.code === 5) { // 5 = NOT_FOUND
|
|
75
|
+
logger.log('WARN',`[Core Utils] Proxy performance doc or 'locks' field not found at ${proxyPerformanceDocPath}. No locks to reset.`);
|
|
76
|
+
} else {
|
|
77
|
+
logger.log('ERROR','[Core Utils] Error resetting proxy locks', { errorMessage: error.message, path: proxyPerformanceDocPath });
|
|
78
|
+
// Do not re-throw, allow orchestration to continue
|
|
79
|
+
}
|
|
75
80
|
}
|
|
76
81
|
}
|
|
77
82
|
|
|
@@ -63,10 +63,15 @@ exports.fetchAndStorePrices = async (firestore, logger, headerManager, proxyMana
|
|
|
63
63
|
const response = await proxyManager.fetch(config.etoroApiUrl, fetchOptions);
|
|
64
64
|
|
|
65
65
|
if (!response || typeof response.text !== 'function') {
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
// Force the response object into the string using JSON.stringify
|
|
67
|
+
const responseString = JSON.stringify(response, null, 2);
|
|
68
|
+
logger.log('ERROR', `[FetchInsightsHelpers] Invalid or incomplete response received. Response object: ${responseString}`);
|
|
69
|
+
|
|
70
|
+
throw new Error(`Invalid response structure received from proxy.`);
|
|
68
71
|
}
|
|
69
72
|
|
|
73
|
+
|
|
74
|
+
|
|
70
75
|
if (!response.ok) {
|
|
71
76
|
const errorBody = await response.text();
|
|
72
77
|
throw new Error(`API returned status ${response.status}: ${errorBody}`);
|
|
@@ -97,7 +97,7 @@ function createDiscoveryOrchestrator(config) {
|
|
|
97
97
|
return async (req, res) => {
|
|
98
98
|
logger.log('INFO', '🚀 Discovery Orchestrator triggered via module...');
|
|
99
99
|
try {
|
|
100
|
-
await firestoreUtils.resetProxyLocks(config.
|
|
100
|
+
await firestoreUtils.resetProxyLocks(config.proxyPerformanceDocPath);
|
|
101
101
|
await runDiscovery('normal', config.discoveryConfig.normal, config);
|
|
102
102
|
await runDiscovery('speculator', config.discoveryConfig.speculator, config);
|
|
103
103
|
res.status(200).send('Discovery orchestration complete.');
|
|
@@ -118,7 +118,7 @@ function createUpdateOrchestrator(config) {
|
|
|
118
118
|
return async (req, res) => {
|
|
119
119
|
logger.log('INFO', '🚀 Update Orchestrator triggered via module...');
|
|
120
120
|
try {
|
|
121
|
-
await firestoreUtils.resetProxyLocks(config.
|
|
121
|
+
await firestoreUtils.resetProxyLocks(config.proxyPerformanceDocPath);
|
|
122
122
|
await runUpdates('normal', config.updateConfig, config);
|
|
123
123
|
await runUpdates('speculator', config.updateConfig, config);
|
|
124
124
|
res.status(200).send('Update orchestration complete.');
|