Skip to content

Commit

Permalink
Fix response to accepted for concurrent generation
Browse files Browse the repository at this point in the history
  • Loading branch information
yma96 committed Dec 6, 2024
1 parent c6a9cd9 commit 5ce8feb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public void destroy()
IOUtils.closeQuietly( client, null );
}

public boolean generate( HistoricalContentDTO content )
public void generate( HistoricalContentDTO content )
{
String buildConfigId = content.getBuildConfigId();
Object lock = buildConfigLocks.computeIfAbsent( buildConfigId, k -> new Object() );
Expand All @@ -166,8 +166,8 @@ public boolean generate( HistoricalContentDTO content )
{
logger.info( "There is already generation process in progress for buildConfigId {}, try lock wait.",
buildConfigId );
// Conflicted generation, just return with expected http response immediately
return false;
// Conflicted generation, just return immediately
return;
}

recordInProgress( buildConfigId );
Expand Down Expand Up @@ -208,7 +208,6 @@ public boolean generate( HistoricalContentDTO content )
logger.error( "Generation future task level failed for buildConfigId {}", buildConfigId, e );
}
}
return true;
}

protected Boolean doGenerate( HistoricalContentDTO content )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@

import static jakarta.ws.rs.core.MediaType.APPLICATION_JSON;
import static jakarta.ws.rs.core.MediaType.APPLICATION_OCTET_STREAM;
import static jakarta.ws.rs.core.Response.Status.CONFLICT;
import static jakarta.ws.rs.core.Response.Status.NOT_FOUND;
import static jakarta.ws.rs.core.Response.accepted;
import static jakarta.ws.rs.core.Response.noContent;
Expand All @@ -75,7 +74,6 @@ public class ArchiveManageResources

@Operation( description = "Generate archive based on tracked content" )
@APIResponse( responseCode = "202", description = "The archive created request is accepted" )
@APIResponse( responseCode = "409", description = "The archive created request is conflicted" )
@RequestBody( description = "The tracked content definition JSON", name = "body", required = true,
content = @Content( mediaType = APPLICATION_JSON,
example = "{" + "\"buildConfigId\": \"XXX\"," + "\"downloads\":" + "[{"
Expand Down Expand Up @@ -106,17 +104,11 @@ public Uni<Response> create( final @Context UriInfo uriInfo, final InputStream b
return fromResponse( message );
}

boolean accepted = controller.generate( content );
controller.generate( content );
return Uni.createFrom()
.item( accepted ?
accepted().type( MediaType.TEXT_PLAIN )
.entity( "Archive created request is accepted." )
.build() :
Response.status( CONFLICT )
.type( MediaType.TEXT_PLAIN )
.entity(
"Another generation with same build config ID was already in progress, request is conflicted." )
.build() );
.item( accepted().type( MediaType.TEXT_PLAIN )
.entity( "Archive created request is accepted." )
.build() );
}

@Operation( description = "Get the status of generating archive based on build config Id" )
Expand Down

0 comments on commit 5ce8feb

Please sign in to comment.