scripter-x 1.0.14 → 1.0.15
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/package.json +1 -1
- package/src/worker.js +11 -5
package/package.json
CHANGED
package/src/worker.js
CHANGED
|
@@ -122,6 +122,7 @@ export class Worker {
|
|
|
122
122
|
const res = { id_no: idNo, status: 'failed', cost: 0, detail: '' };
|
|
123
123
|
|
|
124
124
|
if (this.stats.succeeded >= this.requested) {
|
|
125
|
+
this._emit(slot, { phase: 'done', detail: 'goal reached' });
|
|
125
126
|
res.status = 'cancelled';
|
|
126
127
|
res.detail = 'goal reached';
|
|
127
128
|
return res;
|
|
@@ -133,6 +134,7 @@ export class Worker {
|
|
|
133
134
|
if (this.stats.succeeded >= this.requested) {
|
|
134
135
|
this.log(`goal reached by another slot; releasing ${number.mobile} immediately`);
|
|
135
136
|
this._release(number, Date.now());
|
|
137
|
+
this._emit(slot, { phase: 'done', detail: 'goal reached' });
|
|
136
138
|
res.status = 'cancelled';
|
|
137
139
|
res.detail = 'goal reached';
|
|
138
140
|
return res;
|
|
@@ -150,9 +152,13 @@ export class Worker {
|
|
|
150
152
|
// releaseOnce — the single chokepoint that schedules the provider cancel. Called from
|
|
151
153
|
// every terminal path (fail, success, error). Without this a blocked/errored number
|
|
152
154
|
// could stay rented → we'd be charged.
|
|
153
|
-
const releaseOnce = () => {
|
|
155
|
+
const releaseOnce = (charged = false, doneDetail = 'done') => {
|
|
154
156
|
if (released) return;
|
|
155
157
|
released = true;
|
|
158
|
+
if (charged) {
|
|
159
|
+
this._emit(slot, { phase: 'done', detail: doneDetail });
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
156
162
|
this._emit(slot, { phase: 'cancelling', detail: 'releasing number' });
|
|
157
163
|
this._release(number, rentedAt);
|
|
158
164
|
};
|
|
@@ -163,7 +169,7 @@ export class Worker {
|
|
|
163
169
|
res.cost = charged ? number.cost : 0;
|
|
164
170
|
res.detail = detail;
|
|
165
171
|
this.log(`FAILED ${number.mobile}: ${detail} (charged: ${charged})`);
|
|
166
|
-
releaseOnce();
|
|
172
|
+
releaseOnce(charged, 'failed');
|
|
167
173
|
return res;
|
|
168
174
|
};
|
|
169
175
|
|
|
@@ -234,10 +240,10 @@ export class Worker {
|
|
|
234
240
|
}
|
|
235
241
|
|
|
236
242
|
this._emit(slot, { phase: 'saving', detail: 'saving session' });
|
|
237
|
-
res.status = 'success'; res.cost = number.cost; res.session = session;
|
|
238
243
|
this.log(`SUCCESS ${number.mobile} — session extracted (₹${number.cost})${res.email_linked ? ` + email ${res.linked_email}` : ''}`);
|
|
239
|
-
|
|
240
|
-
|
|
244
|
+
const doneDetail = res.email_linked ? `extracted + ${res.linked_email}` : 'extracted';
|
|
245
|
+
this._emit(slot, { phase: 'done', detail: doneDetail });
|
|
246
|
+
releaseOnce(true, doneDetail); // success still releases the number (OTP already consumed)
|
|
241
247
|
return res;
|
|
242
248
|
} catch (e) {
|
|
243
249
|
// ANY unexpected error → still release the number so we're never charged for a leak
|