forked from Haroldwonder/SwiftRemit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhealth-check-demo.js
More file actions
executable file
·84 lines (71 loc) · 2.08 KB
/
health-check-demo.js
File metadata and controls
executable file
·84 lines (71 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env node
/**
* Health Check Demo for SwiftRemit Smart Contract
*
* This demonstrates how a health check would work in practice.
* Since the contract has compilation issues, this shows the expected behavior.
*/
const { v4: uuidv4 } = require('uuid');
const { createLogger } = require('./examples/logger');
let logger = createLogger('health-check-demo');
// Mock contract health check response
function mockContractHealth() {
return {
operational: true,
timestamp: Math.floor(Date.now() / 1000),
initialized: true
};
}
// Simulate health check with latency
async function checkHealth() {
const start = Date.now();
try {
// Simulate network call
await new Promise(resolve => setTimeout(resolve, Math.random() * 50));
const health = mockContractHealth();
const latency = Date.now() - start;
return {
success: true,
data: health,
latency_ms: latency
};
} catch (error) {
return {
success: false,
error: error.message,
latency_ms: Date.now() - start
};
}
}
// Main demo
async function main() {
const requestId = process.env.REQUEST_ID || uuidv4();
logger = createLogger('health-check-demo', requestId);
logger.info('SwiftRemit Health Check Demo');
// Run 5 health checks
for (let i = 1; i <= 5; i++) {
const result = await checkHealth();
logger.info({
check_num: i,
status: result.success ? '✅ HEALTHY' : '❌ UNHEALTHY',
operational: result.data?.operational,
initialized: result.data?.initialized,
timestamp: result.data?.timestamp,
latency_ms: result.latency_ms,
performance: result.latency_ms < 100 ? '✅ PASS' : '⚠️ SLOW'
}, 'Health check result');
}
logger.info('Health check demo complete!');
logger.info({
expected_response_structure: {
success: true,
data: {
operational: true,
timestamp: 1708545351,
initialized: true
},
error: null
}
}, 'Expected Response Structure');
}
main().catch(err => logger.error({ error: err.message }, 'Demo failed'));