Mark queue as failed and don't try again if something weird happens

This commit is contained in:
nise.moe 2024-02-23 10:36:30 +01:00
parent fd6d23327c
commit 1928eb07cf
5 changed files with 37 additions and 14 deletions

View File

@ -18,7 +18,7 @@ import org.jooq.Identity
import org.jooq.Name
import org.jooq.Record
import org.jooq.Records
import org.jooq.Row8
import org.jooq.Row9
import org.jooq.Schema
import org.jooq.SelectField
import org.jooq.Table
@ -104,6 +104,11 @@ open class UpdateUserQueue(
*/
val ADDED_BY_USER_ID: TableField<UpdateUserQueueRecord, Long?> = createField(DSL.name("added_by_user_id"), SQLDataType.BIGINT, this, "")
/**
* The column <code>public.update_user_queue.has_failed</code>.
*/
val HAS_FAILED: TableField<UpdateUserQueueRecord, Boolean?> = createField(DSL.name("has_failed"), SQLDataType.BOOLEAN.nullable(false).defaultValue(DSL.field(DSL.raw("false"), SQLDataType.BOOLEAN)), this, "")
private constructor(alias: Name, aliased: Table<UpdateUserQueueRecord>?): this(alias, null, null, aliased, null)
private constructor(alias: Name, aliased: Table<UpdateUserQueueRecord>?, parameters: Array<Field<*>?>?): this(alias, null, null, aliased, parameters)
@ -146,18 +151,18 @@ open class UpdateUserQueue(
override fun rename(name: Table<*>): UpdateUserQueue = UpdateUserQueue(name.getQualifiedName(), null)
// -------------------------------------------------------------------------
// Row8 type methods
// Row9 type methods
// -------------------------------------------------------------------------
override fun fieldsRow(): Row8<Int?, Long?, Boolean?, LocalDateTime?, OffsetDateTime?, Int?, Int?, Long?> = super.fieldsRow() as Row8<Int?, Long?, Boolean?, LocalDateTime?, OffsetDateTime?, Int?, Int?, Long?>
override fun fieldsRow(): Row9<Int?, Long?, Boolean?, LocalDateTime?, OffsetDateTime?, Int?, Int?, Long?, Boolean?> = super.fieldsRow() as Row9<Int?, Long?, Boolean?, LocalDateTime?, OffsetDateTime?, Int?, Int?, Long?, Boolean?>
/**
* Convenience mapping calling {@link SelectField#convertFrom(Function)}.
*/
fun <U> mapping(from: (Int?, Long?, Boolean?, LocalDateTime?, OffsetDateTime?, Int?, Int?, Long?) -> U): SelectField<U> = convertFrom(Records.mapping(from))
fun <U> mapping(from: (Int?, Long?, Boolean?, LocalDateTime?, OffsetDateTime?, Int?, Int?, Long?, Boolean?) -> U): SelectField<U> = convertFrom(Records.mapping(from))
/**
* Convenience mapping calling {@link SelectField#convertFrom(Class,
* Function)}.
*/
fun <U> mapping(toType: Class<U>, from: (Int?, Long?, Boolean?, LocalDateTime?, OffsetDateTime?, Int?, Int?, Long?) -> U): SelectField<U> = convertFrom(toType, Records.mapping(from))
fun <U> mapping(toType: Class<U>, from: (Int?, Long?, Boolean?, LocalDateTime?, OffsetDateTime?, Int?, Int?, Long?, Boolean?) -> U): SelectField<U> = convertFrom(toType, Records.mapping(from))
}

View File

@ -11,8 +11,8 @@ import java.time.OffsetDateTime
import org.jooq.Field
import org.jooq.Record1
import org.jooq.Record8
import org.jooq.Row8
import org.jooq.Record9
import org.jooq.Row9
import org.jooq.impl.UpdatableRecordImpl
@ -20,7 +20,7 @@ import org.jooq.impl.UpdatableRecordImpl
* This class is generated by jOOQ.
*/
@Suppress("UNCHECKED_CAST")
open class UpdateUserQueueRecord private constructor() : UpdatableRecordImpl<UpdateUserQueueRecord>(UpdateUserQueue.UPDATE_USER_QUEUE), Record8<Int?, Long?, Boolean?, LocalDateTime?, OffsetDateTime?, Int?, Int?, Long?> {
open class UpdateUserQueueRecord private constructor() : UpdatableRecordImpl<UpdateUserQueueRecord>(UpdateUserQueue.UPDATE_USER_QUEUE), Record9<Int?, Long?, Boolean?, LocalDateTime?, OffsetDateTime?, Int?, Int?, Long?, Boolean?> {
open var id: Int?
set(value): Unit = set(0, value)
@ -54,6 +54,10 @@ open class UpdateUserQueueRecord private constructor() : UpdatableRecordImpl<Upd
set(value): Unit = set(7, value)
get(): Long? = get(7) as Long?
open var hasFailed: Boolean?
set(value): Unit = set(8, value)
get(): Boolean? = get(8) as Boolean?
// -------------------------------------------------------------------------
// Primary key information
// -------------------------------------------------------------------------
@ -61,11 +65,11 @@ open class UpdateUserQueueRecord private constructor() : UpdatableRecordImpl<Upd
override fun key(): Record1<Int?> = super.key() as Record1<Int?>
// -------------------------------------------------------------------------
// Record8 type implementation
// Record9 type implementation
// -------------------------------------------------------------------------
override fun fieldsRow(): Row8<Int?, Long?, Boolean?, LocalDateTime?, OffsetDateTime?, Int?, Int?, Long?> = super.fieldsRow() as Row8<Int?, Long?, Boolean?, LocalDateTime?, OffsetDateTime?, Int?, Int?, Long?>
override fun valuesRow(): Row8<Int?, Long?, Boolean?, LocalDateTime?, OffsetDateTime?, Int?, Int?, Long?> = super.valuesRow() as Row8<Int?, Long?, Boolean?, LocalDateTime?, OffsetDateTime?, Int?, Int?, Long?>
override fun fieldsRow(): Row9<Int?, Long?, Boolean?, LocalDateTime?, OffsetDateTime?, Int?, Int?, Long?, Boolean?> = super.fieldsRow() as Row9<Int?, Long?, Boolean?, LocalDateTime?, OffsetDateTime?, Int?, Int?, Long?, Boolean?>
override fun valuesRow(): Row9<Int?, Long?, Boolean?, LocalDateTime?, OffsetDateTime?, Int?, Int?, Long?, Boolean?> = super.valuesRow() as Row9<Int?, Long?, Boolean?, LocalDateTime?, OffsetDateTime?, Int?, Int?, Long?, Boolean?>
override fun field1(): Field<Int?> = UpdateUserQueue.UPDATE_USER_QUEUE.ID
override fun field2(): Field<Long?> = UpdateUserQueue.UPDATE_USER_QUEUE.USER_ID
override fun field3(): Field<Boolean?> = UpdateUserQueue.UPDATE_USER_QUEUE.PROCESSED
@ -74,6 +78,7 @@ open class UpdateUserQueueRecord private constructor() : UpdatableRecordImpl<Upd
override fun field6(): Field<Int?> = UpdateUserQueue.UPDATE_USER_QUEUE.PROGRESS_CURRENT
override fun field7(): Field<Int?> = UpdateUserQueue.UPDATE_USER_QUEUE.PROGRESS_TOTAL
override fun field8(): Field<Long?> = UpdateUserQueue.UPDATE_USER_QUEUE.ADDED_BY_USER_ID
override fun field9(): Field<Boolean?> = UpdateUserQueue.UPDATE_USER_QUEUE.HAS_FAILED
override fun component1(): Int? = id
override fun component2(): Long = userId
override fun component3(): Boolean? = processed
@ -82,6 +87,7 @@ open class UpdateUserQueueRecord private constructor() : UpdatableRecordImpl<Upd
override fun component6(): Int? = progressCurrent
override fun component7(): Int? = progressTotal
override fun component8(): Long? = addedByUserId
override fun component9(): Boolean? = hasFailed
override fun value1(): Int? = id
override fun value2(): Long = userId
override fun value3(): Boolean? = processed
@ -90,6 +96,7 @@ open class UpdateUserQueueRecord private constructor() : UpdatableRecordImpl<Upd
override fun value6(): Int? = progressCurrent
override fun value7(): Int? = progressTotal
override fun value8(): Long? = addedByUserId
override fun value9(): Boolean? = hasFailed
override fun value1(value: Int?): UpdateUserQueueRecord {
set(0, value)
@ -131,7 +138,12 @@ open class UpdateUserQueueRecord private constructor() : UpdatableRecordImpl<Upd
return this
}
override fun values(value1: Int?, value2: Long?, value3: Boolean?, value4: LocalDateTime?, value5: OffsetDateTime?, value6: Int?, value7: Int?, value8: Long?): UpdateUserQueueRecord {
override fun value9(value: Boolean?): UpdateUserQueueRecord {
set(8, value)
return this
}
override fun values(value1: Int?, value2: Long?, value3: Boolean?, value4: LocalDateTime?, value5: OffsetDateTime?, value6: Int?, value7: Int?, value8: Long?, value9: Boolean?): UpdateUserQueueRecord {
this.value1(value1)
this.value2(value2)
this.value3(value3)
@ -140,13 +152,14 @@ open class UpdateUserQueueRecord private constructor() : UpdatableRecordImpl<Upd
this.value6(value6)
this.value7(value7)
this.value8(value8)
this.value9(value9)
return this
}
/**
* Create a detached, initialised UpdateUserQueueRecord
*/
constructor(id: Int? = null, userId: Long, processed: Boolean? = null, createdAt: LocalDateTime? = null, processedAt: OffsetDateTime? = null, progressCurrent: Int? = null, progressTotal: Int? = null, addedByUserId: Long? = null): this() {
constructor(id: Int? = null, userId: Long, processed: Boolean? = null, createdAt: LocalDateTime? = null, processedAt: OffsetDateTime? = null, progressCurrent: Int? = null, progressTotal: Int? = null, addedByUserId: Long? = null, hasFailed: Boolean? = null): this() {
this.id = id
this.userId = userId
this.processed = processed
@ -155,6 +168,7 @@ open class UpdateUserQueueRecord private constructor() : UpdatableRecordImpl<Upd
this.progressCurrent = progressCurrent
this.progressTotal = progressTotal
this.addedByUserId = addedByUserId
this.hasFailed = hasFailed
resetChangedOnNotNull()
}
}

View File

@ -169,6 +169,7 @@ class ImportScores(
if(topUserScores == null || recentUserScores == null || firstPlaceUserScores == null) {
this.logger.error("Failed to fetch top scores for user with id = $userId")
this.updateUserQueueService.setUserAsProcessed(userId, failed = true)
continue
}

View File

@ -112,10 +112,11 @@ class UpdateUserQueueService(
*
* @param userId The user ID of the user to set as processed.
*/
fun setUserAsProcessed(userId: Long) {
fun setUserAsProcessed(userId: Long, failed: Boolean = false) {
dslContext.update(UPDATE_USER_QUEUE)
.set(UPDATE_USER_QUEUE.PROCESSED, true)
.set(UPDATE_USER_QUEUE.PROCESSED_AT, OffsetDateTime.now(ZoneOffset.UTC))
.set(UPDATE_USER_QUEUE.HAS_FAILED, failed)
.where(UPDATE_USER_QUEUE.USER_ID.eq(userId))
.and(UPDATE_USER_QUEUE.PROCESSED.isFalse)
.execute()

View File

@ -0,0 +1,2 @@
ALTER TABLE public.update_user_queue
ADD COLUMN has_failed boolean DEFAULT false NOT NULL