Skip to content

Commit

Permalink
Restore legacy load
Browse files Browse the repository at this point in the history
Signed-off-by: Paolo Di Tommaso <[email protected]>
  • Loading branch information
pditommaso committed May 31, 2024
1 parent cc27783 commit f0e5f64
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import io.micronaut.http.client.exceptions.HttpClientResponseException
import io.micronaut.runtime.event.ApplicationStartupEvent
import io.micronaut.runtime.event.annotation.EventListener
import io.seqera.wave.core.ContainerDigestPair
import io.seqera.wave.service.builder.BuildRequest
import io.seqera.wave.service.persistence.PersistenceService
import io.seqera.wave.service.persistence.WaveBuildRecord
import io.seqera.wave.service.persistence.WaveContainerRecord
Expand Down Expand Up @@ -109,6 +110,24 @@ class SurrealPersistenceService implements PersistenceService {
WaveBuildRecord loadBuild(String buildId) {
if( !buildId )
throw new IllegalArgumentException("Missing 'buildId' argument")
def result = loadBuild0(buildId)
if( result )
return result
// try to lookup legacy record
final legacyId = BuildRequest.legacyBuildId(buildId)
return legacyId ? loadBuild1(legacyId) : null
}

private WaveBuildRecord loadBuild0(String buildId) {
final query = "select * from wave_build where buildId = '$buildId'"
final json = surrealDb.sqlAsString(getAuthorization(), query)
final type = new TypeReference<ArrayList<SurrealResult<WaveBuildRecord>>>() {}
final data= json ? JacksonHelper.fromJson(json, type) : null
final result = data && data[0].result ? data[0].result[0] : null
return result
}

private WaveBuildRecord loadBuild1(String buildId) {
final query = "select * from wave_build where buildId = '$buildId'"
final json = surrealDb.sqlAsString(getAuthorization(), query)
final type = new TypeReference<ArrayList<SurrealResult<WaveBuildRecord>>>() {}
Expand Down

0 comments on commit f0e5f64

Please sign in to comment.