Skip to content

Commit

Permalink
Register job status using API
Browse files Browse the repository at this point in the history
  • Loading branch information
wkmor1 committed Aug 1, 2023
1 parent 874855f commit 052b1d9
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
33 changes: 33 additions & 0 deletions api.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,39 @@ cors <- function(req, res) {

}

#* @filter secret
function(req, res) {

secret <- identical(req[["argsQuery"]][["secret"]], Sys.getenv("JOB_SECRET"))

if (grepl("job", req[["PATH_INFO"]]) && !secret) {

res[["status"]] <- 401
list(error = "Access token required")

} else {

forward()

}

}

#* Register result of job
#* @tag status
#* @get /healthz
#* @response 200 A json object response
#* @serializer unboxedJSON
function(status) {

cat(status, file = "var/status/success.txt")

cat(format(Sys.time(), usetz = TRUE), file = "status/last-update.txt")

"success"

}

#* Check the liveness of the API
#* @tag status
#* @head /healthz
Expand Down
12 changes: 12 additions & 0 deletions template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ parameters:
required: true
generate: expression
from: "[a-zA-Z0-9]{20}"
- name: JOB_SECRET
required: true
generate: expression
from: "[a-zA-Z0-9]{64}"
metadata:
name: ${APP}
objects:
Expand Down Expand Up @@ -203,6 +207,8 @@ objects:
value: ${FINBIF_WAREHOUSE_QUERY}
- name: FINBIF_EMAIL
value: ${FINBIF_EMAIL}
- name: JOB_SECRET
value: ${JOB_SECRET}
volumes:
- name: ${TMP_DIR}
emptyDir:
Expand Down Expand Up @@ -362,4 +368,10 @@ objects:
value: ${DB}-${BRANCH}
- name: TIMEOUT_IN_HOURS
value: ${TIMEOUT_IN_HOURS}
- name: JOB_SECRET
value: ${JOB_SECRET}
- name: APP_HOSTNAME
value: ${BRANCH}-${APP}.${APP}.svc
- name: APP_PORT
value: ${APP_PORT}
restartPolicy: Never
7 changes: 6 additions & 1 deletion update_indices.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tryCatch(
res <- tryCatch(

{

Expand Down Expand Up @@ -239,3 +239,8 @@ tryCatch(
}

)

httr::GET(
paste0(Sys.getenv("APP_HOSTNAME"), ":", Sys.getenv("APP_PORT")),
query = list(job = res)
)

0 comments on commit 052b1d9

Please sign in to comment.