From cb0c2447799e345555f11f74dbc8d4780eb90e2c Mon Sep 17 00:00:00 2001 From: hrj Date: Mon, 28 Feb 2022 09:30:31 +0530 Subject: [PATCH] in background task, divide total required by number of combinations, and create in multiple iterations Signed-off-by: hrj --- src/main/scala/lc/background/taskThread.scala | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/scala/lc/background/taskThread.scala b/src/main/scala/lc/background/taskThread.scala index bc23d9f..c7f59ce 100644 --- a/src/main/scala/lc/background/taskThread.scala +++ b/src/main/scala/lc/background/taskThread.scala @@ -18,11 +18,15 @@ class BackgroundTask(config: Config, captchaManager: CaptchaManager) { val challengeGCPstmt = Statements.tlStmts.get.challengeGCPstmt challengeGCPstmt.executeUpdate() - for (param <- allParameterCombinations()) { - val imageNum = captchaManager.getCount(param).getOrElse(0) - val countCreate = (config.throttle * 1.1).toInt - imageNum - if (countCreate > 0) { - println(s"Creating $countCreate captchas for $param") + val allCombinations = allParameterCombinations() + val requiredCountPerCombination = Math.max(1, (config.throttle * 1.01) / allCombinations.size).toInt + + for (param <- allCombinations) { + val countExisting = captchaManager.getCount(param).getOrElse(0) + val countRequired = requiredCountPerCombination - countExisting + if (countRequired > 0) { + val countCreate = Math.min(1.0 + requiredCountPerCombination/10.0, countRequired).toInt + println(s"Creating $countCreate of $countRequired captchas for $param") for (i <- 0 until countCreate) { captchaManager.generateChallenge(param)