@sylphx/flow 1.0.0 → 1.0.1
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/CHANGELOG.md +133 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +59554 -0
- package/dist/lancedb.linux-x64-gnu-b7f0jgsz.node +0 -0
- package/dist/lancedb.linux-x64-musl-tgcv22rx.node +0 -0
- package/dist/shared/chunk-25dwp0dp.js +89 -0
- package/dist/shared/chunk-3pjb6063.js +208 -0
- package/dist/shared/chunk-4d6ydpw7.js +2854 -0
- package/dist/shared/chunk-4wjcadjk.js +225 -0
- package/dist/shared/chunk-5j4w74t6.js +30 -0
- package/dist/shared/chunk-5j8m3dh3.js +58 -0
- package/dist/shared/chunk-5thh3qem.js +91 -0
- package/dist/shared/chunk-6g9xy73m.js +252 -0
- package/dist/shared/chunk-7eq34c42.js +23 -0
- package/dist/shared/chunk-c2gwgx3r.js +115 -0
- package/dist/shared/chunk-cjd3mk4c.js +1320 -0
- package/dist/shared/chunk-g5cv6703.js +368 -0
- package/dist/shared/chunk-hpkhykhq.js +574 -0
- package/dist/shared/chunk-m2322pdk.js +122 -0
- package/dist/shared/chunk-nd5fdvaq.js +26 -0
- package/dist/shared/chunk-pgd3m6zf.js +108 -0
- package/dist/shared/chunk-qk8n91hw.js +494 -0
- package/dist/shared/chunk-rkkn8szp.js +16855 -0
- package/dist/shared/chunk-t16rfxh0.js +61 -0
- package/dist/shared/chunk-t4fbfa5v.js +19 -0
- package/dist/shared/chunk-t77h86w6.js +276 -0
- package/dist/shared/chunk-v0ez4aef.js +71 -0
- package/dist/shared/chunk-v29j2r3s.js +32051 -0
- package/dist/shared/chunk-vfbc6ew5.js +765 -0
- package/dist/shared/chunk-vmeqwm1c.js +204 -0
- package/dist/shared/chunk-x66eh37x.js +137 -0
- package/package.json +3 -2
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import"./chunk-5j4w74t6.js";
|
|
2
|
+
|
|
3
|
+
// src/core/loop-controller.ts
|
|
4
|
+
import chalk from "chalk";
|
|
5
|
+
|
|
6
|
+
class LoopController {
|
|
7
|
+
state;
|
|
8
|
+
shouldStop = false;
|
|
9
|
+
constructor() {
|
|
10
|
+
this.state = {
|
|
11
|
+
iteration: 0,
|
|
12
|
+
startTime: new Date,
|
|
13
|
+
successCount: 0,
|
|
14
|
+
errorCount: 0
|
|
15
|
+
};
|
|
16
|
+
this.setupSignalHandlers();
|
|
17
|
+
}
|
|
18
|
+
async run(executor, options) {
|
|
19
|
+
console.log(chalk.cyan.bold(`
|
|
20
|
+
━━━ \uD83D\uDD04 Loop Mode Activated
|
|
21
|
+
`));
|
|
22
|
+
console.log(chalk.dim(` Wait time: ${options.interval}s`));
|
|
23
|
+
console.log(chalk.dim(` Max runs: ${options.maxRuns || "∞"}`));
|
|
24
|
+
console.log(chalk.dim(` Stop: Ctrl+C or max-runs limit
|
|
25
|
+
`));
|
|
26
|
+
while (this.shouldContinue(options)) {
|
|
27
|
+
this.state.iteration++;
|
|
28
|
+
try {
|
|
29
|
+
await this.executeIteration(executor, options);
|
|
30
|
+
} catch (error) {
|
|
31
|
+
this.handleError(error);
|
|
32
|
+
}
|
|
33
|
+
if (this.shouldContinue(options)) {
|
|
34
|
+
await this.waitForNextRun(options);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
this.printSummary();
|
|
38
|
+
}
|
|
39
|
+
async executeIteration(executor, options) {
|
|
40
|
+
const maxDisplay = options.maxRuns || "∞";
|
|
41
|
+
console.log(chalk.cyan(`
|
|
42
|
+
\uD83D\uDD04 Loop iteration ${this.state.iteration}/${maxDisplay}`));
|
|
43
|
+
console.log(chalk.dim(`Started: ${new Date().toLocaleTimeString()}
|
|
44
|
+
`));
|
|
45
|
+
const result = await executor();
|
|
46
|
+
if (result.error || result.exitCode !== 0) {
|
|
47
|
+
this.state.errorCount++;
|
|
48
|
+
console.log(chalk.yellow(`
|
|
49
|
+
⚠️ Task encountered error (continuing...)`));
|
|
50
|
+
} else {
|
|
51
|
+
this.state.successCount++;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
handleError(error) {
|
|
55
|
+
this.state.errorCount++;
|
|
56
|
+
console.error(chalk.yellow(`
|
|
57
|
+
⚠️ Error occurred - continuing to next iteration`));
|
|
58
|
+
console.error(chalk.dim(`Error: ${error.message}
|
|
59
|
+
`));
|
|
60
|
+
}
|
|
61
|
+
async waitForNextRun(options) {
|
|
62
|
+
const maxDisplay = options.maxRuns || "∞";
|
|
63
|
+
const progress = `${this.state.iteration}/${maxDisplay}`;
|
|
64
|
+
console.log(chalk.dim(`
|
|
65
|
+
⏳ Waiting ${options.interval}s until next run... (completed: ${progress})`));
|
|
66
|
+
const startTime = Date.now();
|
|
67
|
+
const endTime = startTime + options.interval * 1000;
|
|
68
|
+
while (Date.now() < endTime && !this.shouldStop) {
|
|
69
|
+
await this.sleep(1000);
|
|
70
|
+
const remaining = Math.ceil((endTime - Date.now()) / 1000);
|
|
71
|
+
if (remaining > 0 && remaining % 10 === 0) {
|
|
72
|
+
process.stdout.write(chalk.dim(`\r⏳ ${remaining}s remaining...`));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (!this.shouldStop) {
|
|
76
|
+
process.stdout.write("\r" + " ".repeat(50) + "\r");
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
shouldContinue(options) {
|
|
80
|
+
if (this.shouldStop)
|
|
81
|
+
return false;
|
|
82
|
+
if (options.maxRuns && this.state.iteration >= options.maxRuns)
|
|
83
|
+
return false;
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
printSummary() {
|
|
87
|
+
const duration = Date.now() - this.state.startTime.getTime();
|
|
88
|
+
const minutes = Math.floor(duration / 60000);
|
|
89
|
+
const seconds = Math.floor(duration % 60000 / 1000);
|
|
90
|
+
console.log(chalk.cyan.bold(`
|
|
91
|
+
━━━ \uD83C\uDFC1 Loop Summary
|
|
92
|
+
`));
|
|
93
|
+
console.log(` Total iterations: ${this.state.iteration}`);
|
|
94
|
+
console.log(` Successful: ${chalk.green(this.state.successCount.toString())}`);
|
|
95
|
+
console.log(` Errors: ${chalk.red(this.state.errorCount.toString())}`);
|
|
96
|
+
console.log(` Duration: ${minutes}m ${seconds}s`);
|
|
97
|
+
console.log();
|
|
98
|
+
}
|
|
99
|
+
setupSignalHandlers() {
|
|
100
|
+
const handler = () => {
|
|
101
|
+
console.log(chalk.yellow(`
|
|
102
|
+
|
|
103
|
+
⚠️ Interrupt received - finishing current iteration...`));
|
|
104
|
+
this.shouldStop = true;
|
|
105
|
+
};
|
|
106
|
+
process.on("SIGINT", handler);
|
|
107
|
+
process.on("SIGTERM", handler);
|
|
108
|
+
}
|
|
109
|
+
sleep(ms) {
|
|
110
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
export {
|
|
114
|
+
LoopController
|
|
115
|
+
};
|