bgrun 3.12.12 → 3.12.13
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/README.md +2 -2
- package/dashboard/lib/runtime.ts +49 -0
- package/package.json +2 -17
- package/src/api.ts +0 -116
- package/src/build.ts +0 -31
- package/src/commands/cleanup.ts +0 -141
- package/src/commands/details.ts +0 -60
- package/src/commands/list.ts +0 -133
- package/src/commands/logs.ts +0 -49
- package/src/commands/run.ts +0 -217
- package/src/commands/watch.ts +0 -223
- package/src/config.ts +0 -37
- package/src/db.ts +0 -422
- package/src/deploy.ts +0 -163
- package/src/deps.ts +0 -126
- package/src/guard.ts +0 -208
- package/src/index.ts +0 -623
- package/src/log-rotation.ts +0 -93
- package/src/logger.ts +0 -40
- package/src/platform.ts +0 -665
- package/src/server.ts +0 -217
- package/src/table.ts +0 -232
- package/src/types.ts +0 -14
- package/src/utils.ts +0 -96
package/src/log-rotation.ts
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Log rotation for bgrun process output files.
|
|
3
|
-
*
|
|
4
|
-
* Ensures log files don't grow unbounded by:
|
|
5
|
-
* 1. Truncating on rotation (restart) — keeping last N lines
|
|
6
|
-
* 2. Size-based rotation — when file exceeds maxBytes, trim to last N lines
|
|
7
|
-
* 3. Periodic rotation check — runs on an interval in the dashboard
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { existsSync, statSync, readFileSync, writeFileSync } from 'fs'
|
|
11
|
-
|
|
12
|
-
const DEFAULT_MAX_BYTES = 10 * 1024 * 1024 // 10 MB
|
|
13
|
-
const DEFAULT_KEEP_LINES = 5000 // Keep last 5000 lines on rotation
|
|
14
|
-
const DEFAULT_CHECK_INTERVAL_MS = 60_000 // Check every 60s
|
|
15
|
-
|
|
16
|
-
/** Rotate a single log file if it exceeds maxBytes */
|
|
17
|
-
export function rotateLogFile(
|
|
18
|
-
filePath: string,
|
|
19
|
-
maxBytes: number = DEFAULT_MAX_BYTES,
|
|
20
|
-
keepLines: number = DEFAULT_KEEP_LINES,
|
|
21
|
-
): boolean {
|
|
22
|
-
try {
|
|
23
|
-
if (!existsSync(filePath)) return false
|
|
24
|
-
|
|
25
|
-
const stat = statSync(filePath)
|
|
26
|
-
if (stat.size <= maxBytes) return false
|
|
27
|
-
|
|
28
|
-
// Read file, keep last N lines
|
|
29
|
-
const content = readFileSync(filePath, 'utf-8')
|
|
30
|
-
const lines = content.split('\n')
|
|
31
|
-
|
|
32
|
-
if (lines.length <= keepLines) return false
|
|
33
|
-
|
|
34
|
-
const truncated = lines.slice(-keepLines)
|
|
35
|
-
const header = `--- [bgrun] Log rotated at ${new Date().toISOString()} (was ${lines.length} lines, ${formatBytes(stat.size)}) ---\n`
|
|
36
|
-
writeFileSync(filePath, header + truncated.join('\n'))
|
|
37
|
-
|
|
38
|
-
return true
|
|
39
|
-
} catch {
|
|
40
|
-
return false
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/** Rotate all log files for all processes */
|
|
45
|
-
export function rotateAllLogs(
|
|
46
|
-
getProcesses: () => Array<{ name: string; stdout_path: string; stderr_path: string }>,
|
|
47
|
-
maxBytes: number = DEFAULT_MAX_BYTES,
|
|
48
|
-
keepLines: number = DEFAULT_KEEP_LINES,
|
|
49
|
-
): { rotated: string[]; checked: number } {
|
|
50
|
-
const processes = getProcesses()
|
|
51
|
-
const rotated: string[] = []
|
|
52
|
-
let checked = 0
|
|
53
|
-
|
|
54
|
-
for (const proc of processes) {
|
|
55
|
-
if (proc.stdout_path) {
|
|
56
|
-
checked++
|
|
57
|
-
if (rotateLogFile(proc.stdout_path, maxBytes, keepLines)) {
|
|
58
|
-
rotated.push(`${proc.name}/stdout`)
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
if (proc.stderr_path) {
|
|
62
|
-
checked++
|
|
63
|
-
if (rotateLogFile(proc.stderr_path, maxBytes, keepLines)) {
|
|
64
|
-
rotated.push(`${proc.name}/stderr`)
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return { rotated, checked }
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/** Start periodic log rotation */
|
|
73
|
-
export function startLogRotation(
|
|
74
|
-
getProcesses: () => Array<{ name: string; stdout_path: string; stderr_path: string }>,
|
|
75
|
-
intervalMs: number = DEFAULT_CHECK_INTERVAL_MS,
|
|
76
|
-
maxBytes: number = DEFAULT_MAX_BYTES,
|
|
77
|
-
keepLines: number = DEFAULT_KEEP_LINES,
|
|
78
|
-
): ReturnType<typeof setInterval> {
|
|
79
|
-
console.log(`[logs] Log rotation active: max ${formatBytes(maxBytes)}/file, keep ${keepLines} lines, check every ${intervalMs / 1000}s`)
|
|
80
|
-
|
|
81
|
-
return setInterval(() => {
|
|
82
|
-
const { rotated } = rotateAllLogs(getProcesses, maxBytes, keepLines)
|
|
83
|
-
if (rotated.length > 0) {
|
|
84
|
-
console.log(`[logs] Rotated ${rotated.length} log(s): ${rotated.join(', ')}`)
|
|
85
|
-
}
|
|
86
|
-
}, intervalMs)
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function formatBytes(bytes: number): string {
|
|
90
|
-
if (bytes >= 1_000_000) return `${(bytes / 1_000_000).toFixed(1)}MB`
|
|
91
|
-
if (bytes >= 1_000) return `${(bytes / 1_000).toFixed(0)}KB`
|
|
92
|
-
return `${bytes}B`
|
|
93
|
-
}
|
package/src/logger.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import boxen from "boxen";
|
|
2
|
-
import chalk from "chalk";
|
|
3
|
-
|
|
4
|
-
export function announce(message: string, title?: string) {
|
|
5
|
-
console.log(
|
|
6
|
-
boxen(message, {
|
|
7
|
-
padding: 1,
|
|
8
|
-
margin: 1,
|
|
9
|
-
borderColor: 'green',
|
|
10
|
-
title: title || "bgrun",
|
|
11
|
-
titleAlignment: 'center',
|
|
12
|
-
borderStyle: 'round'
|
|
13
|
-
})
|
|
14
|
-
);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/** Custom error class so callers can distinguish bgrun errors from unexpected ones */
|
|
18
|
-
export class BgrunError extends Error {
|
|
19
|
-
constructor(message: string) {
|
|
20
|
-
super(message);
|
|
21
|
-
this.name = 'BgrunError';
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function error(message: string | Error): never {
|
|
26
|
-
const text = message instanceof Error ? (message.stack || message.message) : String(message);
|
|
27
|
-
console.error(
|
|
28
|
-
boxen(chalk.red(text), {
|
|
29
|
-
padding: 1,
|
|
30
|
-
margin: 1,
|
|
31
|
-
borderColor: 'red',
|
|
32
|
-
title: "Error",
|
|
33
|
-
titleAlignment: 'center',
|
|
34
|
-
borderStyle: 'double'
|
|
35
|
-
})
|
|
36
|
-
);
|
|
37
|
-
// Throw instead of process.exit() — lets dashboard API handlers catch gracefully
|
|
38
|
-
// CLI entry point has a top-level catch that calls process.exit(1)
|
|
39
|
-
throw new BgrunError(text);
|
|
40
|
-
}
|