Skip to content

Commit

Permalink
Another commit for #71. Looks like the awaitInitialization method nee…
Browse files Browse the repository at this point in the history
…ds to be called after the resources are defined
  • Loading branch information
sapessi committed Nov 21, 2017
1 parent ab7160b commit de73155
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ public class LambdaHandler implements RequestHandler<AwsProxyRequest, AwsProxyRe
public AwsProxyResponse handleRequest(AwsProxyRequest awsProxyRequest, Context context) {
if (!initialized) {
defineRoutes();
// it's important to call the awaitInitialization method not to run into race
// conditions as routes are loaded asynchronously
Spark.awaitInitialization();
initialized = true;
}
return handler.proxy(awsProxyRequest, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import spark.Spark;

import javax.ws.rs.core.Response;
import java.util.UUID;
Expand All @@ -45,6 +46,7 @@ public AwsProxyResponse handleRequest(AwsProxyRequest awsProxyRequest, Context c
try {
handler = SparkLambdaContainerHandler.getAwsProxyHandler();
defineResources();
Spark.awaitInitialization();
} catch (ContainerInitializationException e) {
log.error("Cannot initialize Spark application", e);
return null;
Expand Down

0 comments on commit de73155

Please sign in to comment.