Fix job deletion bug, add performance tests.

This commit is contained in:
Greyson Parrelli
2024-07-18 10:12:33 -04:00
committed by Nicholas Tinsley
parent 86cf8200b5
commit 36dface175
6 changed files with 264 additions and 7 deletions

View File

@@ -197,6 +197,40 @@ class JobDatabase(
.readToList { it.toJobSpec() }
}
@Synchronized
fun getJobSpecsByKeys(keys: Collection<String>): List<JobSpec> {
if (keys.isEmpty()) {
return emptyList()
}
val output: MutableList<JobSpec> = ArrayList(keys.size)
for (query in SqlUtil.buildCollectionQuery(Jobs.JOB_SPEC_ID, keys)) {
readableDatabase
.select()
.from(Jobs.TABLE_NAME)
.where(query.where, query.whereArgs)
.run()
.forEach {
output += it.toJobSpec()
}
}
return output
}
@Synchronized
fun getMostEligibleJobInQueue(queue: String): JobSpec? {
return readableDatabase
.select()
.from(Jobs.TABLE_NAME)
.where("${Jobs.QUEUE_KEY} = ?", queue)
.orderBy("${Jobs.PRIORITY} DESC, ${Jobs.CREATE_TIME} ASC, ${Jobs.ID} ASC")
.limit(1)
.run()
.readToSingleObject { it.toJobSpec() }
}
@Synchronized
fun getAllMatchingFilter(predicate: Predicate<JobSpec>): List<JobSpec> {
val output: MutableList<JobSpec> = mutableListOf()