Package dev.dokimos.server.repository
Interface TraceEvalJobRepository
- All Superinterfaces:
org.springframework.data.repository.CrudRepository<TraceEvalJob,,UUID> org.springframework.data.jpa.repository.JpaRepository<TraceEvalJob,,UUID> org.springframework.data.repository.ListCrudRepository<TraceEvalJob,,UUID> org.springframework.data.repository.ListPagingAndSortingRepository<TraceEvalJob,,UUID> org.springframework.data.repository.PagingAndSortingRepository<TraceEvalJob,,UUID> org.springframework.data.repository.query.QueryByExampleExecutor<TraceEvalJob>,org.springframework.data.repository.Repository<TraceEvalJob,UUID>
public interface TraceEvalJobRepository
extends org.springframework.data.jpa.repository.JpaRepository<TraceEvalJob,UUID>
-
Method Summary
Modifier and TypeMethodDescriptionclaimNext(int maxAttempts) Atomically claims the oldest pending job below the retry ceiling usingFOR UPDATE SKIP LOCKED, so multiple worker instances each pick a distinct job instead of blocking on, or double-processing, the same row.findByStatus(TraceEvalJobStatus status) findByTracePk(UUID tracePk) Jobs for the spans of one trace, used by the per-trace detail view.intrequeueStaleClaims(Instant cutoff) Returns jobs claimed before the cutoff to PENDING so a job orphaned by a crashed worker is picked up again rather than stranded in CLAIMED forever.Methods inherited from interface org.springframework.data.repository.CrudRepository
count, delete, deleteAll, deleteAll, deleteAllById, deleteById, existsById, findById, saveMethods inherited from interface org.springframework.data.jpa.repository.JpaRepository
deleteAllByIdInBatch, deleteAllInBatch, deleteAllInBatch, deleteInBatch, findAll, findAll, flush, getById, getOne, getReferenceById, saveAllAndFlush, saveAndFlushMethods inherited from interface org.springframework.data.repository.ListCrudRepository
findAll, findAllById, saveAllMethods inherited from interface org.springframework.data.repository.ListPagingAndSortingRepository
findAllMethods inherited from interface org.springframework.data.repository.PagingAndSortingRepository
findAllMethods inherited from interface org.springframework.data.repository.query.QueryByExampleExecutor
count, exists, findAll, findBy, findOne
-
Method Details
-
findByTracePk
@Query("SELECT j FROM TraceEvalJob j WHERE j.span.trace.id = :tracePk ORDER BY j.createdAt ASC") List<TraceEvalJob> findByTracePk(@Param("tracePk") UUID tracePk) Jobs for the spans of one trace, used by the per-trace detail view. -
findByStatus
-
claimNext
@Query(value="SELECT * FROM trace_eval_jobs\nWHERE status = \'PENDING\' AND attempt_count < :maxAttempts\nORDER BY created_at ASC\nLIMIT 1\nFOR UPDATE SKIP LOCKED\n", nativeQuery=true) Optional<TraceEvalJob> claimNext(@Param("maxAttempts") int maxAttempts) Atomically claims the oldest pending job below the retry ceiling usingFOR UPDATE SKIP LOCKED, so multiple worker instances each pick a distinct job instead of blocking on, or double-processing, the same row. Must run inside a transaction.- Parameters:
maxAttempts- the retry ceiling; jobs at or above this count are skipped- Returns:
- the locked candidate job, if any
-
requeueStaleClaims
@Modifying @Query("UPDATE TraceEvalJob j\nSET j.status = dev.dokimos.server.entity.TraceEvalJobStatus.PENDING\nWHERE j.status = dev.dokimos.server.entity.TraceEvalJobStatus.CLAIMED\nAND j.claimedAt < :cutoff\n") int requeueStaleClaims(@Param("cutoff") Instant cutoff) Returns jobs claimed before the cutoff to PENDING so a job orphaned by a crashed worker is picked up again rather than stranded in CLAIMED forever. The attempt count is left as-is, so the retry ceiling still bounds how many times a job is reclaimed.- Parameters:
cutoff- jobs claimed before this instant are requeued- Returns:
- the number of jobs requeued
-