Skip to content

Commit

Permalink
430: implement health check db sync (#129)
Browse files Browse the repository at this point in the history
* add health check endpoint to db sync

* use cosmossync reference

* add health check import

* add missing kotlin dependency

* add library for optional

* remove irrelevant dependency
  • Loading branch information
dancing-goats authored and candace-campbell committed Jul 31, 2023
1 parent 6027033 commit fbb86d0
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/remote-cd-trigger-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ jobs:
owner: 'cdcent',
repo: 'data-exchange-upload-devops',
workflow_id: '${{ inputs.WORKFLOW }}',
ref: 'main',
ref: 'upload-291/bulk-file-upload-pipeline',
inputs: {
DATA_EXCHANGE_UPLOAD_REF: '${{ inputs.REF }}'
DATA_EXCHANGE_UPLOAD_REF: 'ccampbell-test'
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,22 @@
import com.microsoft.azure.functions.annotation.*;
import com.microsoft.azure.functions.*;
import gov.cdc.ocio.cosmossync.functions.CosmosSyncFunction;
import gov.cdc.ocio.cosmossync.functions.HealthCheckFunction;
import java.util.Optional;

public class FunctionJavaWrappers {

@FunctionName("HealthCheck")
public HttpResponseMessage healthCheck(
@HttpTrigger(
name = "req",
methods = {HttpMethod.GET},
route = "health",
authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request,
final ExecutionContext context) {
return new HealthCheckFunction().run(request, context);
}

@FunctionName("CosmosQueueProcessor")
public void run(
@QueueTrigger(name = "msg",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package gov.cdc.ocio.cosmossync.functions

import com.azure.cosmos.models.CosmosQueryRequestOptions
import com.microsoft.azure.functions.ExecutionContext
import com.microsoft.azure.functions.HttpRequestMessage
import com.microsoft.azure.functions.HttpResponseMessage
import com.microsoft.azure.functions.HttpStatus
import gov.cdc.ocio.cosmossync.cosmos.CosmosClientManager
import gov.cdc.ocio.cosmossync.model.Item
import java.util.*
import java.util.logging.Logger

class HealthCheckFunction {

fun run(
request: HttpRequestMessage<Optional<String>>,
context: ExecutionContext
): HttpResponseMessage {

try {
val cosmosClient = CosmosClientManager.getCosmosClient()

val databaseName = System.getenv("CosmosDbDatabaseName")
val containerName = System.getenv("CosmosDbContainerName")

val cosmosDB = cosmosClient.getDatabase(databaseName)
val container = cosmosDB.getContainer(containerName)

val sqlQuery = "select * from $containerName t OFFSET 0 LIMIT 1"
val items = container.queryItems(
sqlQuery, CosmosQueryRequestOptions(),
Item::class.java
)

return request
.createResponseBuilder(HttpStatus.OK)
.build()

} catch (ex: Throwable) {

return request
.createResponseBuilder(HttpStatus.INTERNAL_SERVER_ERROR)
.build()
}
}
}

0 comments on commit fbb86d0

Please sign in to comment.