bulltrackers-module 1.0.270 → 1.0.271
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.
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @fileoverview Build Reporter & Auto-Runner.
|
|
3
3
|
* Generates a "Pre-Flight" report of what the computation system WILL do.
|
|
4
4
|
* REFACTORED: Strict 5-category reporting with date-based exclusion logic.
|
|
5
|
-
* UPDATED: Added
|
|
5
|
+
* UPDATED: Added transactional locking to prevent duplicate reports on concurrent cold starts.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
const { analyzeDateExecution } = require('../WorkflowOrchestrator');
|
|
@@ -45,24 +45,47 @@ function isDateBeforeAvailability(dateStr, calcManifest) {
|
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
47
|
* AUTO-RUN ENTRY POINT
|
|
48
|
+
* UPDATED: Uses transactional locking to prevent race conditions.
|
|
48
49
|
*/
|
|
49
50
|
async function ensureBuildReport(config, dependencies, manifest) {
|
|
50
51
|
const { db, logger } = dependencies;
|
|
51
52
|
const now = new Date();
|
|
52
53
|
const buildId = `v${packageVersion}_${now.getFullYear()}-${String(now.getMonth()+1).padStart(2,'0')}-${String(now.getDate()).padStart(2,'0')}_${String(now.getHours()).padStart(2,'0')}-${String(now.getMinutes()).padStart(2,'0')}-${String(now.getSeconds()).padStart(2,'0')}`;
|
|
53
|
-
|
|
54
|
+
|
|
55
|
+
// Lock document specific to this version
|
|
56
|
+
const lockRef = db.collection('computation_build_records').doc(`init_lock_v${packageVersion}`);
|
|
54
57
|
|
|
55
58
|
try {
|
|
56
|
-
|
|
57
|
-
const
|
|
59
|
+
// Transaction: "Hey I am deploying" check
|
|
60
|
+
const shouldRun = await db.runTransaction(async (t) => {
|
|
61
|
+
const doc = await t.get(lockRef);
|
|
62
|
+
|
|
63
|
+
if (doc.exists) {
|
|
64
|
+
// Someone else beat us to it
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Claim the lock
|
|
69
|
+
t.set(lockRef, {
|
|
70
|
+
status: 'IN_PROGRESS',
|
|
71
|
+
startedAt: new Date(),
|
|
72
|
+
workerId: process.env.K_REVISION || 'unknown',
|
|
73
|
+
buildId: buildId
|
|
74
|
+
});
|
|
75
|
+
return true;
|
|
76
|
+
});
|
|
58
77
|
|
|
59
|
-
if (
|
|
60
|
-
logger.log('INFO', `[BuildReporter]
|
|
78
|
+
if (!shouldRun) {
|
|
79
|
+
logger.log('INFO', `[BuildReporter] 🔒 Report for v${packageVersion} is already being generated (Locked). Skipping.`);
|
|
61
80
|
return;
|
|
62
81
|
}
|
|
63
82
|
|
|
64
|
-
logger.log('INFO', `[BuildReporter] 🚀
|
|
83
|
+
logger.log('INFO', `[BuildReporter] 🚀 Lock Acquired. Running Pre-flight Report for v${packageVersion}...`);
|
|
84
|
+
|
|
65
85
|
await generateBuildReport(config, dependencies, manifest, 90, buildId);
|
|
86
|
+
|
|
87
|
+
// Optional: Update lock to completed (fire-and-forget update)
|
|
88
|
+
lockRef.update({ status: 'COMPLETED', completedAt: new Date() }).catch(() => {});
|
|
66
89
|
|
|
67
90
|
} catch (e) {
|
|
68
91
|
logger.log('ERROR', `[BuildReporter] Auto-run check failed: ${e.message}`);
|