bulltrackers-module 1.0.738 → 1.0.740
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/core-api.js +88 -0
- package/functions/computation-system-v2/docs/admin.md +44 -18
- package/functions/computation-system-v2/docs/plans.md +588 -0
- package/functions/computation-system-v2/framework/core/Manifest.js +25 -1
- package/functions/computation-system-v2/framework/data/DataFetcher.js +34 -2
- package/functions/computation-system-v2/framework/data/SchemaRegistry.js +31 -7
- package/functions/computation-system-v2/framework/execution/Orchestrator.js +36 -21
- package/functions/computation-system-v2/framework/execution/RemoteTaskRunner.js +74 -13
- package/functions/computation-system-v2/handlers/adminTest.js +1 -2
- package/functions/computation-system-v2/index.js +4 -176
- package/package.json +1 -1
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Core System API
|
|
3
|
+
* Contains the business logic and orchestrator management.
|
|
4
|
+
* Separated from index.js to prevent circular dependencies with handlers.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const { Orchestrator } = require('./framework');
|
|
8
|
+
const config = require('./config/bulltrackers.config');
|
|
9
|
+
const { ManifestBuilder } = require('./framework/core/Manifest');
|
|
10
|
+
const { Computation } = require('./framework/core/Computation');
|
|
11
|
+
|
|
12
|
+
// Add computations to config
|
|
13
|
+
config.computations = [
|
|
14
|
+
require('./computations/UserPortfolioSummary'),
|
|
15
|
+
require('./computations/PopularInvestorProfileMetrics'),
|
|
16
|
+
require('./computations/PopularInvestorRiskAssessment'),
|
|
17
|
+
require('./computations/PopularInvestorRiskMetrics'),
|
|
18
|
+
// Add more computations here as they're migrated
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
// Singleton orchestrator instance
|
|
22
|
+
let orchestrator = null;
|
|
23
|
+
|
|
24
|
+
async function getOrchestrator(customConfig = null, logger = null) {
|
|
25
|
+
if (!orchestrator || customConfig) {
|
|
26
|
+
const cfg = customConfig || config;
|
|
27
|
+
orchestrator = new Orchestrator(cfg, logger);
|
|
28
|
+
}
|
|
29
|
+
return orchestrator;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async function analyze(options) {
|
|
33
|
+
const { date, config: customConfig = null, logger = null } = options;
|
|
34
|
+
const orch = await getOrchestrator(customConfig, logger);
|
|
35
|
+
return orch.analyze({ date });
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function execute(options) {
|
|
39
|
+
const { date, pass = null, computation = null, dryRun = false, entities = null, config: customConfig = null, logger = null } = options;
|
|
40
|
+
const orch = await getOrchestrator(customConfig, logger);
|
|
41
|
+
return orch.execute({ date, pass, computation, dryRun, entities });
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async function runComputation(options) {
|
|
45
|
+
const { date, computation, entityIds = null, dryRun = false, force = false, useWorkerPool, config: customConfig = null, logger = null } = options;
|
|
46
|
+
const orch = await getOrchestrator(customConfig, logger);
|
|
47
|
+
|
|
48
|
+
if (!orch.manifest) await orch.initialize();
|
|
49
|
+
|
|
50
|
+
const normalizedName = computation.toLowerCase().replace(/[^a-z0-9]/g, '');
|
|
51
|
+
const entry = orch.manifest.find(c => c.name === normalizedName);
|
|
52
|
+
|
|
53
|
+
if (!entry) throw new Error(`Computation not found: ${computation}`);
|
|
54
|
+
|
|
55
|
+
return orch.runSingle(entry, date, { entityIds, dryRun, force, useWorkerPool });
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async function getManifest(options = {}) {
|
|
59
|
+
const { config: customConfig = null, logger = null } = options;
|
|
60
|
+
const orch = await getOrchestrator(customConfig, logger);
|
|
61
|
+
if (!orch.manifest) await orch.initialize();
|
|
62
|
+
return orch.manifest;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async function warmCache(options = {}) {
|
|
66
|
+
const { config: customConfig = null, logger = null } = options;
|
|
67
|
+
const orch = await getOrchestrator(customConfig, logger);
|
|
68
|
+
const allTables = Object.keys(orch.config.tables);
|
|
69
|
+
return orch.schemaRegistry.warmCache(allTables);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function reset() {
|
|
73
|
+
orchestrator = null;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
module.exports = {
|
|
77
|
+
analyze,
|
|
78
|
+
execute,
|
|
79
|
+
runComputation,
|
|
80
|
+
getManifest,
|
|
81
|
+
warmCache,
|
|
82
|
+
reset,
|
|
83
|
+
getOrchestrator,
|
|
84
|
+
config,
|
|
85
|
+
ManifestBuilder,
|
|
86
|
+
Computation,
|
|
87
|
+
...require('./framework')
|
|
88
|
+
};
|
|
@@ -1,9 +1,35 @@
|
|
|
1
|
+
Here is the updated `admin.md` file. I have replaced the hardcoded placeholder URL with a dynamic variable (`$FUNCTION_URL`) and corrected the token generation command to remove the invalid `--audiences` flag.
|
|
2
|
+
|
|
3
|
+
This version is copy-paste ready for your terminal.
|
|
4
|
+
|
|
5
|
+
### `computation-system-v2/docs/admin.md`
|
|
6
|
+
|
|
7
|
+
```markdown
|
|
1
8
|
# Admin Test Endpoint
|
|
2
9
|
|
|
3
10
|
## Deploy
|
|
4
11
|
|
|
5
12
|
```bash
|
|
6
13
|
node deploy.mjs ComputeAdminTest
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Setup (Run Before Testing)
|
|
18
|
+
|
|
19
|
+
First, retrieve your function's actual URL and generate an authentication token.
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
# 1. Get the Function URL dynamically
|
|
23
|
+
# (Adjust region if not in europe-west1)
|
|
24
|
+
FUNCTION_URL=$(gcloud functions describe compute-admin-test \
|
|
25
|
+
--region=europe-west1 \
|
|
26
|
+
--format="value(serviceConfig.uri)")
|
|
27
|
+
|
|
28
|
+
# 2. Generate an Identity Token (Standard User account)
|
|
29
|
+
TOKEN=$(gcloud auth print-identity-token)
|
|
30
|
+
|
|
31
|
+
echo "Targeting: $FUNCTION_URL"
|
|
32
|
+
|
|
7
33
|
```
|
|
8
34
|
|
|
9
35
|
## Usage Examples
|
|
@@ -11,81 +37,81 @@ node deploy.mjs ComputeAdminTest
|
|
|
11
37
|
### 1. Check System Status
|
|
12
38
|
|
|
13
39
|
```bash
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
curl -X POST \
|
|
17
|
-
"https://europe-west1-stocks-12345.cloudfunctions.net/compute-admin-test" \
|
|
40
|
+
curl -X POST "$FUNCTION_URL" \
|
|
18
41
|
-H "Authorization: Bearer $TOKEN" \
|
|
19
42
|
-H "Content-Type: application/json" \
|
|
20
43
|
-d '{"action": "status"}'
|
|
44
|
+
|
|
21
45
|
```
|
|
22
46
|
|
|
23
47
|
### 2. Analyze What Would Run
|
|
24
48
|
|
|
25
49
|
```bash
|
|
26
|
-
curl -X POST \
|
|
27
|
-
"https://europe-west1-stocks-12345.cloudfunctions.net/compute-admin-test" \
|
|
50
|
+
curl -X POST "$FUNCTION_URL" \
|
|
28
51
|
-H "Authorization: Bearer $TOKEN" \
|
|
29
52
|
-H "Content-Type: application/json" \
|
|
30
53
|
-d '{"action": "analyze", "date": "2026-01-25"}'
|
|
54
|
+
|
|
31
55
|
```
|
|
32
56
|
|
|
33
57
|
### 3. Run Full Computation
|
|
34
58
|
|
|
35
59
|
```bash
|
|
36
|
-
curl -X POST \
|
|
37
|
-
"https://europe-west1-stocks-12345.cloudfunctions.net/compute-admin-test" \
|
|
60
|
+
curl -X POST "$FUNCTION_URL" \
|
|
38
61
|
-H "Authorization: Bearer $TOKEN" \
|
|
39
62
|
-H "Content-Type: application/json" \
|
|
40
63
|
-d '{"action": "run", "computation": "UserPortfolioSummary", "date": "2026-01-25", "force": true}'
|
|
64
|
+
|
|
41
65
|
```
|
|
42
66
|
|
|
43
67
|
### 4. Run Limited Test
|
|
44
68
|
|
|
45
69
|
```bash
|
|
46
|
-
curl -X POST \
|
|
47
|
-
"https://europe-west1-stocks-12345.cloudfunctions.net/compute-admin-test" \
|
|
70
|
+
curl -X POST "$FUNCTION_URL" \
|
|
48
71
|
-H "Authorization: Bearer $TOKEN" \
|
|
49
72
|
-H "Content-Type: application/json" \
|
|
50
73
|
-d '{"action": "run_limited", "computation": "UserPortfolioSummary", "date": "2026-01-25", "limit": 5}'
|
|
74
|
+
|
|
51
75
|
```
|
|
52
76
|
|
|
53
77
|
### 5. Test Specific Entities
|
|
54
78
|
|
|
55
79
|
```bash
|
|
56
|
-
curl -X POST \
|
|
57
|
-
"https://europe-west1-stocks-12345.cloudfunctions.net/compute-admin-test" \
|
|
80
|
+
curl -X POST "$FUNCTION_URL" \
|
|
58
81
|
-H "Authorization: Bearer $TOKEN" \
|
|
59
82
|
-H "Content-Type: application/json" \
|
|
60
83
|
-d '{"action": "run", "computation": "UserPortfolioSummary", "date": "2026-01-25", "entityIds": ["user-123", "user-456"], "force": true}'
|
|
84
|
+
|
|
61
85
|
```
|
|
62
86
|
|
|
63
87
|
### 6. Test Worker Directly
|
|
64
88
|
|
|
65
89
|
```bash
|
|
66
|
-
curl -X POST \
|
|
67
|
-
"https://europe-west1-stocks-12345.cloudfunctions.net/compute-admin-test" \
|
|
90
|
+
curl -X POST "$FUNCTION_URL" \
|
|
68
91
|
-H "Authorization: Bearer $TOKEN" \
|
|
69
92
|
-H "Content-Type: application/json" \
|
|
70
93
|
-d '{"action": "test_worker", "computation": "UserPortfolioSummary", "date": "2026-01-25", "entityIds": ["user-123"]}'
|
|
94
|
+
|
|
71
95
|
```
|
|
72
96
|
|
|
73
97
|
### 7. Test with Worker Pool Override
|
|
74
98
|
|
|
75
99
|
```bash
|
|
76
|
-
curl -X POST \
|
|
77
|
-
"https://europe-west1-stocks-12345.cloudfunctions.net/compute-admin-test" \
|
|
100
|
+
curl -X POST "$FUNCTION_URL" \
|
|
78
101
|
-H "Authorization: Bearer $TOKEN" \
|
|
79
102
|
-H "Content-Type: application/json" \
|
|
80
103
|
-d '{"action": "run", "computation": "UserPortfolioSummary", "date": "2026-01-25", "useWorkerPool": true, "force": true}'
|
|
104
|
+
|
|
81
105
|
```
|
|
82
106
|
|
|
83
107
|
## Available Actions
|
|
84
108
|
|
|
85
109
|
| Action | Description |
|
|
86
|
-
|
|
110
|
+
| --- | --- |
|
|
87
111
|
| `status` | List all computations and system status |
|
|
88
112
|
| `analyze` | Check what would run for a given date |
|
|
89
113
|
| `run` | Execute a full computation |
|
|
90
114
|
| `run_limited` | Execute on N random entities (safer for testing) |
|
|
91
|
-
| `test_worker` | Direct test of worker function logic |
|
|
115
|
+
| `test_worker` | Direct test of worker function logic |
|
|
116
|
+
|
|
117
|
+
```
|