| 30209 |
amit.gupta |
1 |
package com.smartdukaan.cron.scheduled;
|
|
|
2 |
|
|
|
3 |
import com.spice.profitmandi.dao.repository.fofo.ActivatedImeiRepository;
|
|
|
4 |
import org.apache.logging.log4j.LogManager;
|
|
|
5 |
import org.apache.logging.log4j.Logger;
|
|
|
6 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
7 |
import org.springframework.stereotype.Service;
|
|
|
8 |
|
|
|
9 |
import java.time.LocalDate;
|
|
|
10 |
import java.util.List;
|
|
|
11 |
import java.util.Map;
|
|
|
12 |
|
|
|
13 |
@Service
|
|
|
14 |
public class OppoImeiActivationService {
|
|
|
15 |
|
|
|
16 |
private static final Logger LOGGER = LogManager.getLogger(OppoImeiActivationService.class);
|
| 37788 |
amit |
17 |
|
|
|
18 |
private static final String BRAND = "Oppo";
|
| 30209 |
amit.gupta |
19 |
@Autowired
|
|
|
20 |
ActivatedImeiRepository activatedImeiRepository;
|
| 30372 |
amit.gupta |
21 |
@Autowired
|
|
|
22 |
CheckOppoWarrantyTask checkOppoWarrantyTask;
|
| 30209 |
amit.gupta |
23 |
|
|
|
24 |
public void updateActivationDate(List<String> imeis) throws Exception {
|
| 30372 |
amit.gupta |
25 |
Map<String, LocalDate> imeisDateMap = checkOppoWarrantyTask.checkWarranty(imeis);
|
| 36253 |
amit |
26 |
imeisDateMap.forEach((serialNumber, date) -> {
|
|
|
27 |
LOGGER.info("Serial Number {} Date {}", serialNumber, date);
|
|
|
28 |
activatedImeiRepository.saveActivation(serialNumber, date != null ? date.atStartOfDay() : null);
|
| 30372 |
amit.gupta |
29 |
});
|
| 37788 |
amit |
30 |
// NOTHING answered means the failure was OURS, not a verdict on these imeis, so do
|
|
|
31 |
// not stamp them. A per-imei failure is normal and still rests below; a whole chunk
|
|
|
32 |
// failing is infrastructure -- a dead driver, an unreadable jar resource, the site
|
|
|
33 |
// refusing every request -- and stamping it spends the pool on an outage. That is
|
|
|
34 |
// exactly what happened on 2026-09-22: a ZipException on every WebDriver command
|
|
|
35 |
// burned 3,920 realme and 4,824 oppo imeis in one day for 0 and 96 dates against a
|
|
|
36 |
// normal 76-100%, and because the rows were stamped they will not be re-asked until
|
|
|
37 |
// their rest expires. Leaving them unstamped costs a re-ask of the SAME chunk on the
|
|
|
38 |
// next tick, which is loud and self-limiting, instead of quietly consuming the day.
|
|
|
39 |
if (imeisDateMap.isEmpty() && imeis.size() > 1) {
|
|
|
40 |
LOGGER.error("{} answered none of {} imeis - treating as infrastructure failure and"
|
|
|
41 |
+ " leaving them unstamped rather than resting the whole chunk", BRAND, imeis.size());
|
|
|
42 |
return;
|
|
|
43 |
}
|
| 37565 |
amit |
44 |
restUnanswered(imeis, imeisDateMap);
|
| 30372 |
amit.gupta |
45 |
}
|
|
|
46 |
|
| 37565 |
amit |
47 |
/**
|
|
|
48 |
* Stamp the imeis that never reached an answer, so the chunk advances past them.
|
|
|
49 |
*
|
|
|
50 |
* checkWarranty already records a null date for a lookup the portal ANSWERED with no
|
|
|
51 |
* activation, so what is left here is genuine failure: an exception, a captcha never
|
|
|
52 |
* broken, a dead driver. Those wrote no row at all, which left createTimestamp
|
|
|
53 |
* untouched and the imei immediately due again.
|
|
|
54 |
*
|
|
|
55 |
* Under the old snapshotted once-a-day pass that was harmless -- the pass had already
|
|
|
56 |
* walked past them, so they came back tomorrow either way. Under a 20-second tick the
|
|
|
57 |
* pool query IS the cursor, so an unstamped imei is handed back twenty seconds later
|
|
|
58 |
* and the batch never advances. That is the 4.5-asks-per-imei runaway measured on
|
|
|
59 |
* 29-Aug, and at this cadence it is 15x tighter than the 5-minute version that caused it.
|
|
|
60 |
*
|
|
|
61 |
* saveActivation(serial, null) bumps createTimestamp without claiming a date, and it
|
|
|
62 |
* cannot erase one: the setter is only reached for a non-null timestamp. So a failure
|
|
|
63 |
* costs exactly one retry, tomorrow.
|
|
|
64 |
*/
|
|
|
65 |
private void restUnanswered(List<String> imeis, Map<String, LocalDate> answered) {
|
|
|
66 |
for (String serialNumber : imeis) {
|
|
|
67 |
if (!answered.containsKey(serialNumber)) {
|
|
|
68 |
LOGGER.info("Serial Number {} unanswered, resting until tomorrow", serialNumber);
|
|
|
69 |
activatedImeiRepository.saveActivation(serialNumber, null);
|
|
|
70 |
}
|
|
|
71 |
}
|
|
|
72 |
}
|
|
|
73 |
|
| 36253 |
amit |
74 |
}
|