Skip to content

Commit

Permalink
logic
Browse files Browse the repository at this point in the history
  • Loading branch information
drhelius committed Aug 16, 2023
1 parent 1c459a1 commit 6be8978
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 79 deletions.
47 changes: 11 additions & 36 deletions src/main/java/com/drhelius/Function.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
public class Function {

private static HttpStatus status = HttpStatus.OK;
private static InitClient initClient = new InitClient();
private static LazyClient lazyClient = new LazyClient();

@FunctionName("Warmup")
Expand All @@ -25,39 +24,16 @@ public void warmup( @WarmupTrigger Object warmupContext, ExecutionContext contex
context.getLogger().info("Function App instance is warm 🌞🌞🌞");
}

@FunctionName("RunInit")
public HttpResponseMessage runInit(
@FunctionName("Run")
public HttpResponseMessage run(
@HttpTrigger(
name = "req",
methods = {HttpMethod.GET, HttpMethod.POST},
authLevel = AuthorizationLevel.ANONYMOUS,
route = "runinit")
route = "run")
HttpRequestMessage<Optional<String>> request,
final ExecutionContext context) {
context.getLogger().info("RunInit HTTP trigger processing a request...");

final String query = request.getQueryParameters().get("name");
final String name = request.getBody().orElse(query);

initClient.run();

if (name == null) {
return request.createResponseBuilder(HttpStatus.BAD_REQUEST).body("Please pass a name on the query string or in the request body").build();
} else {
return request.createResponseBuilder(HttpStatus.OK).body("Hello, " + name).build();
}
}

@FunctionName("RunLazy")
public HttpResponseMessage runLazy(
@HttpTrigger(
name = "req",
methods = {HttpMethod.GET, HttpMethod.POST},
authLevel = AuthorizationLevel.ANONYMOUS,
route = "runlazy")
HttpRequestMessage<Optional<String>> request,
final ExecutionContext context) {
context.getLogger().info("RunLazy HTTP trigger processing a request...");
context.getLogger().info("Run HTTP trigger processing a request...");

final String query = request.getQueryParameters().get("name");
final String name = request.getBody().orElse(query);
Expand All @@ -71,17 +47,16 @@ public HttpResponseMessage runLazy(
}
}


@FunctionName("ChangeStatus")
public HttpResponseMessage changeStatus(
@FunctionName("ChangeHealth")
public HttpResponseMessage changeHealth(
@HttpTrigger(
name = "req",
methods = {HttpMethod.GET, HttpMethod.POST},
authLevel = AuthorizationLevel.ANONYMOUS,
route = "status")
route = "changehealth")
HttpRequestMessage<Optional<String>> request,
final ExecutionContext context) {
context.getLogger().info("ChangeStatus HTTP trigger processing a request...");
context.getLogger().info("ChangeHealth HTTP trigger processing a request...");

final String query = request.getQueryParameters().get("code");
final String statusString = request.getBody().orElse(query);
Expand All @@ -92,7 +67,7 @@ public HttpResponseMessage changeStatus(
status = HttpStatus.valueOf(Integer.parseInt(statusString));
}

return request.createResponseBuilder(HttpStatus.OK).body("Status changed to " + status.toString()).build();
return request.createResponseBuilder(HttpStatus.OK).body("CustomHealth changed to " + status.toString()).build();
}

@FunctionName("CustomHealth")
Expand All @@ -106,7 +81,7 @@ public HttpResponseMessage customHealth(
final ExecutionContext context) {
context.getLogger().info("CustomHealth HTTP trigger processing a request...");

return request.createResponseBuilder(status).body("Status is " + status.toString()).build();
return request.createResponseBuilder(status).body("CustomHealth is " + status.toString()).build();
}

@FunctionName("Health")
Expand All @@ -120,7 +95,7 @@ public HttpResponseMessage health(
final ExecutionContext context) {
context.getLogger().info("Health HTTP trigger processing a request...");

HttpStatus ret = initClient.isReady() ? HttpStatus.OK : HttpStatus.INTERNAL_SERVER_ERROR;
HttpStatus ret = lazyClient.isReady() ? HttpStatus.OK : HttpStatus.INTERNAL_SERVER_ERROR;

context.getLogger().info("Health is " + ret.toString());

Expand Down
42 changes: 0 additions & 42 deletions src/main/java/com/drhelius/InitClient.java

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/java/com/drhelius/LazyClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public void run() {
}

public synchronized void init() {
int milliseconds = 30000;
int milliseconds = 10000;

if (!isReady) {
System.out.println("LazyClient Waiting " + milliseconds + " milliseconds to initialize the client");
Expand Down

0 comments on commit 6be8978

Please sign in to comment.