simplify logic for background task

Signed-off-by: hrj <harshad.rj@gmail.com>
This commit is contained in:
hrj 2022-02-24 20:06:20 +05:30
parent 6758ec3acf
commit 497b88f0d3
1 changed files with 10 additions and 6 deletions

View File

@ -18,13 +18,17 @@ class BackgroundTask(config: Config, captcha: Captcha) {
val challengeGCPstmt = Statements.tlStmts.get.challengeGCPstmt val challengeGCPstmt = Statements.tlStmts.get.challengeGCPstmt
challengeGCPstmt.executeUpdate() challengeGCPstmt.executeUpdate()
val imageNum = Statements.tlStmts.get.getCountChallengeTable.executeQuery() val imageNumResult = Statements.tlStmts.get.getCountChallengeTable.executeQuery()
var throttleIn = (config.throttle * 1.1).toInt val imageNum = if (imageNumResult.next()) {
if (imageNum.next()) imageNumResult.getInt("total")
throttleIn = (throttleIn - imageNum.getInt("total")) } else {
while (0 < throttleIn) { 0
}
val throttle = (config.throttle * 1.1).toInt - imageNum
for (i <- 0 until throttle) {
captcha.generateChallenge(getRandomParam()) captcha.generateChallenge(getRandomParam())
throttleIn -= 1
} }
} catch { case exception: Exception => println(exception) } } catch { case exception: Exception => println(exception) }
} }