|
28 | 28 | let aborted = false; |
29 | 29 | let successfulRequests = 0; |
30 | 30 | let failedRequests = 0; |
| 31 | + let inProgressRequests = 0; |
31 | 32 |
|
32 | 33 | // Setup Abort Handling (Ctrl+C) |
33 | 34 | process.on("SIGINT", () => { |
34 | 35 | console.log("\nAborting request creation..."); |
35 | 36 | aborted = true; |
36 | 37 | }); |
37 | 38 |
|
38 | | - // Setup Progress Bar |
39 | | - const progressBar = new cliProgress.SingleBar( |
40 | | - {}, |
| 39 | + // Create a multi-bar container |
| 40 | + const multibar = new cliProgress.MultiBar( |
| 41 | + { |
| 42 | + clearOnComplete: false, |
| 43 | + hideCursor: true, |
| 44 | + format: |
| 45 | + " {bar} | {percentage}% | S: {successful}, F: {failed}, IP: {inProgress} | {value}/{total}", |
| 46 | + }, |
41 | 47 | cliProgress.Presets.shades_classic, |
42 | 48 | ); |
43 | 49 |
|
| 50 | + const progressBar = multibar.create(TOTAL_REQUESTS, 0, { |
| 51 | + successful: 0, |
| 52 | + failed: 0, |
| 53 | + inProgress: 0, |
| 54 | + }); |
| 55 | + |
44 | 56 | try { |
45 | 57 | const epkSignatureProvider = new EthereumPrivateKeySignatureProvider({ |
46 | 58 | method: Types.Signature.METHOD.ECDSA, |
|
66 | 78 | console.log( |
67 | 79 | `Attempting to create ${TOTAL_REQUESTS} requests with concurrency ${CONCURRENCY_LIMIT}...`, |
68 | 80 | ); |
69 | | - progressBar.start(TOTAL_REQUESTS, 0); |
70 | 81 |
|
71 | 82 | for (let i = 0; i < TOTAL_REQUESTS; i++) { |
72 | 83 | if (aborted) { |
73 | 84 | console.log(`Skipping remaining requests due to abort signal.`); |
74 | | - break; // Stop adding new tasks if aborted |
| 85 | + break; |
75 | 86 | } |
76 | 87 |
|
77 | 88 | creationPromises.push( |
78 | 89 | limit(async () => { |
79 | | - // Double-check abort flag before starting the async operation |
80 | | - if (aborted) { |
81 | | - return; |
82 | | - } |
| 90 | + if (aborted) return; |
83 | 91 |
|
84 | 92 | try { |
85 | | - // Use a unique identifier or timestamp if content needs variation |
| 93 | + // Increment in-progress counter and update progress bar |
| 94 | + inProgressRequests++; |
| 95 | + progressBar.update(successfulRequests + failedRequests, { |
| 96 | + successful: successfulRequests, |
| 97 | + failed: failedRequests, |
| 98 | + inProgress: inProgressRequests, |
| 99 | + }); |
| 100 | + |
86 | 101 | const uniqueContent = `Request #${i + 1} - ${Date.now()}`; |
87 | 102 |
|
88 | 103 | const requestCreateParameters = { |
|
128 | 143 | const requestData = await request.waitForConfirmation(); |
129 | 144 | successfulRequests++; |
130 | 145 | } catch (error) { |
131 | | - console.error( |
132 | | - `\nFailed to create request: ${error.message || error}`, |
133 | | - ); |
| 146 | + const errorMessage = error.message || error.toString(); |
| 147 | + // Simplified error output to avoid console spam |
| 148 | + console.error(`\nRequest failed: ${errorMessage.split("\n")[0]}`); |
134 | 149 | failedRequests++; |
135 | 150 | } finally { |
136 | | - // Ensure progress bar updates even if aborted after starting the task |
137 | | - if (!aborted) { |
138 | | - progressBar.increment(); |
139 | | - } |
| 151 | + inProgressRequests--; // Decrement in-progress counter |
| 152 | + progressBar.update(successfulRequests + failedRequests, { |
| 153 | + successful: successfulRequests, |
| 154 | + failed: failedRequests, |
| 155 | + inProgress: inProgressRequests, |
| 156 | + }); |
140 | 157 | } |
141 | 158 | }), |
142 | 159 | ); |
143 | 160 | } |
144 | 161 |
|
145 | | - // Wait for all queued promises to settle |
146 | 162 | await Promise.all(creationPromises); |
147 | 163 | } catch (error) { |
148 | 164 | console.error(`\nAn unexpected error occurred: ${error.message || error}`); |
149 | | - aborted = true; // Stop progress bar on unexpected errors |
| 165 | + aborted = true; |
150 | 166 | } finally { |
151 | | - progressBar.stop(); |
| 167 | + // Stop the progress bar |
| 168 | + multibar.stop(); |
| 169 | + |
152 | 170 | console.log("\n--- Request Creation Summary ---"); |
153 | 171 | console.log(`Total attempted: ${successfulRequests + failedRequests}`); |
154 | 172 | console.log(`Successful: ${successfulRequests}`); |
155 | 173 | console.log(`Failed: ${failedRequests}`); |
| 174 | + |
156 | 175 | if (aborted && successfulRequests + failedRequests < TOTAL_REQUESTS) { |
157 | 176 | console.log( |
158 | 177 | `Process aborted. ${ |
|
0 commit comments