refactor(processing): remove unused processing start field
processing_started_at 没有任何判据消费(终态只看尝试上限),删除字段、仓储接口与方法、主泵写入、重放清理、SELECT/映射与 H2 fixture,并新增 V7 DROP COLUMN;V1–V6 历史迁移不动。 验证:./gradlew test 123 tests / 0 fail;V7 的 DROP 与最终 schema 断言需真实 PG,本机无 Docker 时 FlywayMigrationTest 按既有 assumeTrue 跳过。
This commit is contained in:
@@ -59,9 +59,6 @@ interface ProcStateRepository {
|
||||
/** 当前队头:还没处理完的消息里 ID 最小的那条。 */
|
||||
fun headUnfinished(): ProcState?
|
||||
|
||||
/** 首次开始处理时记下稳定起点;重试不覆盖。 */
|
||||
fun markProcessingStartedIfAbsent(msgId: Long, now: Instant)
|
||||
|
||||
/** 给消息绑定业务身份;返回 false 表示这个身份已经被另一条消息占了(业务重复)。 */
|
||||
fun tryBindIdentity(msgId: Long, identityKey: String): Boolean
|
||||
|
||||
|
||||
+2
-13
@@ -107,16 +107,6 @@ class JdbcProcStateRepository(
|
||||
::mapProcState,
|
||||
)
|
||||
|
||||
override fun markProcessingStartedIfAbsent(msgId: Long, now: Instant) {
|
||||
ds.update(
|
||||
"UPDATE proc_state SET processing_started_at = ? WHERE msg_id = ? AND processing_started_at IS NULL",
|
||||
{ ps ->
|
||||
ps.setTimestamp(1, now.toSqlTimestamp())
|
||||
ps.setLong(2, msgId)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
override fun tryBindIdentity(msgId: Long, identityKey: String): Boolean {
|
||||
ownerOfIdentity(identityKey)?.let { owner ->
|
||||
return owner == msgId
|
||||
@@ -286,7 +276,7 @@ class JdbcProcStateRepository(
|
||||
if (errorClasses.isEmpty()) return 0
|
||||
val placeholders = errorClasses.joinToString(",") { "?" }
|
||||
return ds.update(
|
||||
"UPDATE proc_state SET state = 'PENDING', attempts = 0, next_attempt_at = NULL, processing_started_at = NULL, updated_at = ? " +
|
||||
"UPDATE proc_state SET state = 'PENDING', attempts = 0, next_attempt_at = NULL, updated_at = ? " +
|
||||
"WHERE state IN ('FAILED', 'DEAD') AND error_class IN ($placeholders)",
|
||||
{ ps ->
|
||||
ps.setTimestamp(1, clock.instant().toSqlTimestamp())
|
||||
@@ -339,7 +329,6 @@ class JdbcProcStateRepository(
|
||||
backfillError = rs.getString("backfill_error"),
|
||||
backfillAbandonedAt = rs.getInstant("backfill_abandoned_at"),
|
||||
backfillAbandonedReason = rs.getString("backfill_abandoned_reason"),
|
||||
processingStartedAt = rs.getInstant("processing_started_at"),
|
||||
updatedAt = rs.getInstant("updated_at") ?: clock.instant(),
|
||||
)
|
||||
|
||||
@@ -347,7 +336,7 @@ class JdbcProcStateRepository(
|
||||
const val SELECT_PROC =
|
||||
"SELECT msg_id, state, identity_key, attempts, next_attempt_at, error_class, last_error, " +
|
||||
"received_at, enqueued_at, backfill_at, backfill_next_at, backfill_attempts, backfill_error, " +
|
||||
"backfill_abandoned_at, backfill_abandoned_reason, processing_started_at, updated_at FROM proc_state"
|
||||
"backfill_abandoned_at, backfill_abandoned_reason, updated_at FROM proc_state"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -84,12 +84,6 @@ class StubProcState : ProcStateRepository {
|
||||
override fun headUnfinished(): ProcState? =
|
||||
rows.values.filter { it.state == ProcStatus.PENDING || it.state == ProcStatus.FAILED }.minByOrNull { it.msgId }
|
||||
|
||||
override fun markProcessingStartedIfAbsent(msgId: Long, now: Instant) {
|
||||
rows[msgId]?.let { row ->
|
||||
if (row.processingStartedAt == null) rows[msgId] = row.copy(processingStartedAt = now)
|
||||
}
|
||||
}
|
||||
|
||||
override fun tryBindIdentity(msgId: Long, identityKey: String): Boolean {
|
||||
val owner = bound[identityKey]
|
||||
if (owner != null && owner != msgId) return false
|
||||
@@ -216,7 +210,7 @@ class StubProcState : ProcStateRepository {
|
||||
var n = 0
|
||||
rows.forEach { (id, s) ->
|
||||
if (s.errorClass in errorClasses && (s.state == ProcStatus.FAILED || s.state == ProcStatus.DEAD)) {
|
||||
rows[id] = s.copy(state = ProcStatus.PENDING, attempts = 0, nextAttemptAt = null, processingStartedAt = null)
|
||||
rows[id] = s.copy(state = ProcStatus.PENDING, attempts = 0, nextAttemptAt = null)
|
||||
n++
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user