bulltrackers-module 1.0.733 → 1.0.734
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/functions/computation-system-v2/README.md +152 -0
- package/functions/computation-system-v2/computations/PopularInvestorProfileMetrics.js +720 -0
- package/functions/computation-system-v2/computations/PopularInvestorRiskAssessment.js +176 -0
- package/functions/computation-system-v2/computations/PopularInvestorRiskMetrics.js +294 -0
- package/functions/computation-system-v2/computations/TestComputation.js +46 -0
- package/functions/computation-system-v2/computations/UserPortfolioSummary.js +172 -0
- package/functions/computation-system-v2/config/bulltrackers.config.js +317 -0
- package/functions/computation-system-v2/framework/core/Computation.js +73 -0
- package/functions/computation-system-v2/framework/core/Manifest.js +223 -0
- package/functions/computation-system-v2/framework/core/RuleInjector.js +53 -0
- package/functions/computation-system-v2/framework/core/Rules.js +231 -0
- package/functions/computation-system-v2/framework/core/RunAnalyzer.js +163 -0
- package/functions/computation-system-v2/framework/cost/CostTracker.js +154 -0
- package/functions/computation-system-v2/framework/data/DataFetcher.js +399 -0
- package/functions/computation-system-v2/framework/data/QueryBuilder.js +232 -0
- package/functions/computation-system-v2/framework/data/SchemaRegistry.js +287 -0
- package/functions/computation-system-v2/framework/execution/Orchestrator.js +498 -0
- package/functions/computation-system-v2/framework/execution/TaskRunner.js +35 -0
- package/functions/computation-system-v2/framework/execution/middleware/CostTrackerMiddleware.js +32 -0
- package/functions/computation-system-v2/framework/execution/middleware/LineageMiddleware.js +32 -0
- package/functions/computation-system-v2/framework/execution/middleware/Middleware.js +14 -0
- package/functions/computation-system-v2/framework/execution/middleware/ProfilerMiddleware.js +47 -0
- package/functions/computation-system-v2/framework/index.js +45 -0
- package/functions/computation-system-v2/framework/lineage/LineageTracker.js +147 -0
- package/functions/computation-system-v2/framework/monitoring/Profiler.js +80 -0
- package/functions/computation-system-v2/framework/resilience/Checkpointer.js +66 -0
- package/functions/computation-system-v2/framework/scheduling/ScheduleValidator.js +327 -0
- package/functions/computation-system-v2/framework/storage/StateRepository.js +286 -0
- package/functions/computation-system-v2/framework/storage/StorageManager.js +469 -0
- package/functions/computation-system-v2/framework/storage/index.js +9 -0
- package/functions/computation-system-v2/framework/testing/ComputationTester.js +86 -0
- package/functions/computation-system-v2/framework/utils/Graph.js +205 -0
- package/functions/computation-system-v2/handlers/dispatcher.js +109 -0
- package/functions/computation-system-v2/handlers/index.js +23 -0
- package/functions/computation-system-v2/handlers/onDemand.js +289 -0
- package/functions/computation-system-v2/handlers/scheduler.js +327 -0
- package/functions/computation-system-v2/index.js +163 -0
- package/functions/computation-system-v2/rules/index.js +49 -0
- package/functions/computation-system-v2/rules/instruments.js +465 -0
- package/functions/computation-system-v2/rules/metrics.js +304 -0
- package/functions/computation-system-v2/rules/portfolio.js +534 -0
- package/functions/computation-system-v2/rules/rankings.js +655 -0
- package/functions/computation-system-v2/rules/social.js +562 -0
- package/functions/computation-system-v2/rules/trades.js +545 -0
- package/functions/computation-system-v2/scripts/migrate-sectors.js +73 -0
- package/functions/computation-system-v2/test/test-dispatcher.js +317 -0
- package/functions/computation-system-v2/test/test-framework.js +500 -0
- package/functions/computation-system-v2/test/test-real-execution.js +166 -0
- package/functions/computation-system-v2/test/test-real-integration.js +194 -0
- package/functions/computation-system-v2/test/test-refactor-e2e.js +131 -0
- package/functions/computation-system-v2/test/test-results.json +31 -0
- package/functions/computation-system-v2/test/test-risk-metrics-computation.js +329 -0
- package/functions/computation-system-v2/test/test-scheduler.js +204 -0
- package/functions/computation-system-v2/test/test-storage.js +449 -0
- package/functions/orchestrator/index.js +18 -26
- package/package.json +3 -2
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview Main orchestration logic.
|
|
3
3
|
* REFACTORED: Implements 'Active Scheduling' via Cloud Tasks to enforce 1-hour gaps.
|
|
4
|
-
* This allows the Workflow to finish immediately while Cloud Tasks manages the pacing.
|
|
5
4
|
*/
|
|
6
5
|
const { checkDiscoveryNeed, getDiscoveryCandidates, dispatchDiscovery } = require('./helpers/discovery_helpers');
|
|
7
6
|
const { getUpdateTargets, dispatchUpdates } = require('./helpers/update_helpers');
|
|
@@ -11,14 +10,11 @@ const { CloudTasksClient } = require('@google-cloud/tasks');
|
|
|
11
10
|
// Initialize Cloud Tasks Client
|
|
12
11
|
const cloudTasksClient = new CloudTasksClient();
|
|
13
12
|
|
|
14
|
-
// ---
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
// Default Dispatcher URL (can be overridden by environment variable)
|
|
20
|
-
dispatcherUrl: process.env.DISPATCHER_URL || 'https://us-central1-stocks-12345.cloudfunctions.net/dispatcher'
|
|
21
|
-
};
|
|
13
|
+
// --- CONFIGURATION (Now via Env Vars) ---
|
|
14
|
+
// These are injected by deploy.mjs based on config.mjs
|
|
15
|
+
const QUEUE_NAME = process.env.ORCHESTRATOR_QUEUE || 'task-engine-queue';
|
|
16
|
+
const LOCATION = process.env.GCP_REGION || 'europe-west1';
|
|
17
|
+
const PROJECT = process.env.GCP_PROJECT_ID;
|
|
22
18
|
|
|
23
19
|
/**
|
|
24
20
|
* ENTRY POINT: HTTP Handler for Workflow Interaction
|
|
@@ -38,9 +34,10 @@ async function handleOrchestratorHttp(req, res, dependencies, config) {
|
|
|
38
34
|
}
|
|
39
35
|
|
|
40
36
|
// Determine self-URL for callback (Cloud Task needs to call this function back)
|
|
41
|
-
// We use the
|
|
37
|
+
// We use the env var passed by GCF (FUNCTION_URI) or construct it manually
|
|
42
38
|
const orchestratorUrl = orchestratorUrlOverride ||
|
|
43
|
-
|
|
39
|
+
process.env.FUNCTION_URI ||
|
|
40
|
+
`https://${LOCATION}-${PROJECT}.cloudfunctions.net/${process.env.K_SERVICE || 'orchestrator-http'}`;
|
|
44
41
|
|
|
45
42
|
const result = await planDailyUpdates(userType, date, windows || 10, config, dependencies, orchestratorUrl);
|
|
46
43
|
res.status(200).send(result);
|
|
@@ -68,16 +65,12 @@ async function handleOrchestratorHttp(req, res, dependencies, config) {
|
|
|
68
65
|
|
|
69
66
|
/**
|
|
70
67
|
* LOGIC: Plan the updates (Split into windows AND Schedule Execution)
|
|
71
|
-
* 1. Fetches all users needing updates.
|
|
72
|
-
* 2. Shuffles them.
|
|
73
|
-
* 3. Splits them into 'n' windows.
|
|
74
|
-
* 4. Schedules Cloud Tasks for each window with a 1-hour delay between them.
|
|
75
68
|
*/
|
|
76
69
|
async function planDailyUpdates(userType, date, numberOfWindows, config, deps, orchestratorUrl) {
|
|
77
70
|
const { logger, db } = deps;
|
|
78
71
|
|
|
79
|
-
// Use
|
|
80
|
-
const parentQueue = cloudTasksClient.queuePath(
|
|
72
|
+
// Use Configured Queue
|
|
73
|
+
const parentQueue = cloudTasksClient.queuePath(PROJECT, LOCATION, QUEUE_NAME);
|
|
81
74
|
|
|
82
75
|
// 1. Get ALL targets
|
|
83
76
|
const now = new Date();
|
|
@@ -105,7 +98,6 @@ async function planDailyUpdates(userType, date, numberOfWindows, config, deps, o
|
|
|
105
98
|
const planId = `plan_${userType}_${date}`;
|
|
106
99
|
const batchWriter = db.batch();
|
|
107
100
|
|
|
108
|
-
// We collect task creation promises to await them at the end
|
|
109
101
|
const tasksToCreate = [];
|
|
110
102
|
|
|
111
103
|
for (let i = 0; i < numberOfWindows; i++) {
|
|
@@ -150,7 +142,7 @@ async function planDailyUpdates(userType, date, numberOfWindows, config, deps, o
|
|
|
150
142
|
url: orchestratorUrl,
|
|
151
143
|
headers: { 'Content-Type': 'application/json' },
|
|
152
144
|
body: Buffer.from(JSON.stringify(taskPayload)).toString('base64'),
|
|
153
|
-
// Use OIDC if service account is available in env
|
|
145
|
+
// Use OIDC if service account is available in env
|
|
154
146
|
oidcToken: process.env.GCP_SERVICE_ACCOUNT_EMAIL
|
|
155
147
|
? { serviceAccountEmail: process.env.GCP_SERVICE_ACCOUNT_EMAIL }
|
|
156
148
|
: undefined
|
|
@@ -165,18 +157,21 @@ async function planDailyUpdates(userType, date, numberOfWindows, config, deps, o
|
|
|
165
157
|
}
|
|
166
158
|
}
|
|
167
159
|
|
|
168
|
-
// Commit Firestore Writes First
|
|
160
|
+
// Commit Firestore Writes First
|
|
169
161
|
await batchWriter.commit();
|
|
170
162
|
logger.log('SUCCESS', `[Orchestrator Plan] Plan ${planId} saved to Firestore.`);
|
|
171
163
|
|
|
172
164
|
// Dispatch Cloud Tasks
|
|
173
|
-
logger.log('INFO', `[Orchestrator Plan] Scheduling ${tasksToCreate.length} tasks for ${userType}...`);
|
|
165
|
+
logger.log('INFO', `[Orchestrator Plan] Scheduling ${tasksToCreate.length} tasks for ${userType} to queue ${QUEUE_NAME}...`);
|
|
174
166
|
|
|
175
167
|
const scheduleResults = await Promise.allSettled(tasksToCreate.map(req => cloudTasksClient.createTask(req)));
|
|
176
168
|
|
|
177
169
|
const failedCount = scheduleResults.filter(r => r.status === 'rejected').length;
|
|
178
170
|
if (failedCount > 0) {
|
|
179
171
|
logger.log('ERROR', `[Orchestrator Plan] Failed to schedule ${failedCount} tasks.`);
|
|
172
|
+
scheduleResults.forEach((r, idx) => {
|
|
173
|
+
if (r.status === 'rejected') logger.log('ERROR', `Task ${idx} error:`, r.reason);
|
|
174
|
+
});
|
|
180
175
|
}
|
|
181
176
|
|
|
182
177
|
return {
|
|
@@ -190,7 +185,6 @@ async function planDailyUpdates(userType, date, numberOfWindows, config, deps, o
|
|
|
190
185
|
|
|
191
186
|
/**
|
|
192
187
|
* LOGIC: Execute a specific window
|
|
193
|
-
* Triggered by Cloud Tasks when the schedule time arrives.
|
|
194
188
|
*/
|
|
195
189
|
async function executeUpdateWindow(planId, windowId, userType, config, deps) {
|
|
196
190
|
const { logger, db } = deps;
|
|
@@ -205,7 +199,7 @@ async function executeUpdateWindow(planId, windowId, userType, config, deps) {
|
|
|
205
199
|
|
|
206
200
|
const data = windowDoc.data();
|
|
207
201
|
|
|
208
|
-
// Idempotency
|
|
202
|
+
// Idempotency
|
|
209
203
|
if (data.status === 'completed') {
|
|
210
204
|
logger.log('WARN', `[Orchestrator Execute] Window ${windowId} already completed. Skipping.`);
|
|
211
205
|
return { dispatchedCount: 0, status: 'already_completed' };
|
|
@@ -228,8 +222,7 @@ async function executeUpdateWindow(planId, windowId, userType, config, deps) {
|
|
|
228
222
|
return { dispatchedCount: targets.length, status: 'success' };
|
|
229
223
|
}
|
|
230
224
|
|
|
231
|
-
// --- Legacy
|
|
232
|
-
|
|
225
|
+
// --- Legacy Wrappers ---
|
|
233
226
|
async function runDiscoveryOrchestrator(config, deps) {
|
|
234
227
|
const { logger, firestoreUtils } = deps;
|
|
235
228
|
logger.log('INFO', '🚀 Discovery Orchestrator triggered...');
|
|
@@ -257,7 +250,6 @@ async function runUpdateOrchestrator(config, deps) {
|
|
|
257
250
|
}
|
|
258
251
|
|
|
259
252
|
async function runDiscovery(userType, userConfig, globalConfig, deps) {
|
|
260
|
-
const { logger } = deps;
|
|
261
253
|
const { needsDiscovery, blocksToFill } = await checkDiscoveryNeed(userType, userConfig, deps);
|
|
262
254
|
if (!needsDiscovery) return;
|
|
263
255
|
const candidates = await getDiscoveryCandidates(userType, blocksToFill, userConfig, deps);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bulltrackers-module",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.734",
|
|
4
4
|
"description": "Helper Functions for Bulltrackers.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"files": [
|
|
@@ -28,7 +28,8 @@
|
|
|
28
28
|
"functions/maintenance/backfill-pi-alert-history",
|
|
29
29
|
"functions/maintenance/backfill-pi-page-views",
|
|
30
30
|
"functions/maintenance/backfill-pi-ratings",
|
|
31
|
-
"functions/maintenance/backfill-watchlist-membership"
|
|
31
|
+
"functions/maintenance/backfill-watchlist-membership",
|
|
32
|
+
"functions/computation-system-v2/"
|
|
32
33
|
],
|
|
33
34
|
"keywords": [
|
|
34
35
|
"bulltrackers",
|