Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mrc 5600 - status endpoint #8

Merged
merged 10 commits into from
Aug 20, 2024
Merged

Mrc 5600 - status endpoint #8

merged 10 commits into from
Aug 20, 2024

Conversation

absternator
Copy link
Contributor

@absternator absternator commented Aug 8, 2024

This PR adds the status endpoint. THe endpoint returns the status of a run with the following info: status, queue_position, time_queued, time_started, time_complete, packet_id, logs..... all these will return null if not available

@absternator absternator requested a review from M-Kusumgar August 8, 2024 11:16
@M-Kusumgar M-Kusumgar changed the base branch from main to mrc-5585-submit-endpoint August 8, 2024 11:26
Copy link
Contributor

@M-Kusumgar M-Kusumgar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking really good, got some feedback but after that lets see what rich thinks about this, im happy with it!

R/api.R Outdated
Comment on lines 106 to 110
##' state root :: root
##' state queue :: queue
report_run_status <- function(root, queue, job_id) {
queue$get_status(job_id)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you dont use root here, can just remove it

R/queue.R Outdated
Comment on lines 83 to 84
time_started = if (!is.na(times[2])) scalar(times[2]) else NULL,
time_complete = if (!is.na(times[3])) scalar(times[3]) else NULL,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think jsonlite (package we use for serialising to json) converts NA to null so i think will be fine

Suggested change
time_started = if (!is.na(times[2])) scalar(times[2]) else NULL,
time_complete = if (!is.na(times[3])) scalar(times[3]) else NULL,
time_started = scalar(times[2]),
time_complete = scalar(times[3]),

if you want to test how something will look in json form you can run jsonlite::toJSON on it

R/queue.R Outdated
time_queued = scalar(times[1]),
time_started = if (!is.na(times[2])) scalar(times[2]) else NULL,
time_complete = if (!is.na(times[3])) scalar(times[3]) else NULL,
packet_id = if (status == "COMPLETE") scalar(rrq::rrq_task_result(job_id, controller = self$controller)) else NULL,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we should also handle the error case here, a task status can also be "ERROR", i found all the statuses here: https://github.com/mrc-ide/rrq/blob/ba2784057e8ad83e304ac9ae44081110c6b3d19c/R/common.R

for now we can ignore the other statuses

R/queue.R Outdated
Comment on lines 32 to 34
log_dir_name <- "runner-logs"
dir.create(log_dir_name, showWarnings = FALSE)
worker_config <- rrq::rrq_worker_config(heartbeat_period = 10, logdir = log_dir_name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont think the logs should be at root level, this is the git repo, we've put all the worker stuff in .packit when the workers come up, i think .packit/logs is a suitable place because then we'll have .packit/workers for the worker roots and .packit/logs for the logs

but maybe lets wait for what rich thinks

Copy link
Contributor

@M-Kusumgar M-Kusumgar Aug 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@richfitz so had another think about this, 2 potential options can be:

  1. ./.packit/logs as log dir
  2. we can have the logs dir in /worker-logs at root level in the docker container which could be a logs volume shared by the workers?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really don't mind, so long as packit itself can't read them directly - only over the api. You could make this another command line switch perhaps, though it really only needs setting before the first worker ever turns up, it doesn't need doing each time as it is persisted in redis.

I wonder if using .packit/ will be confusing as this is an orderly detail so instead do

/logs/worker
/logs/task

as your directory, and add VOLUME /logs to the dockerfile?

@absternator absternator requested a review from richfitz August 8, 2024 12:44
@absternator absternator changed the base branch from mrc-5585-submit-endpoint to main August 16, 2024 13:00
@absternator absternator requested a review from M-Kusumgar August 16, 2024 14:55
Copy link
Contributor

@M-Kusumgar M-Kusumgar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left a couple small comments, also i think something is still auto formatting and making the PR diff noisy

.gitignore Outdated
@@ -15,3 +15,4 @@ docs
.valgrind_ignore
inst/doc
pkgdown
logs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should not be needed

R/queue.R Outdated
Comment on lines 38 to 40
log_dir_name <- "logs/worker"
dir.create(log_dir_name, showWarnings = FALSE)
worker_config <- rrq::rrq_worker_config(heartbeat_period = 10, logdir = log_dir_name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is what i was talking about with the tempfile thing, if the logdir is instead an optional arg of the initialize function (so logdir = NULL in the function arg) then in our tests we can create a temp folder for them using tempfile or tempdir and we can pass in that path into the queue initialize, also if we dont pass it in then the logging can be disabled as not all the tests need it

tempfile or tempdir are great because the folders also get cleaned up after the tests so we dont need to deal with any of that

@absternator absternator requested a review from M-Kusumgar August 19, 2024 14:38
Copy link
Contributor

@M-Kusumgar M-Kusumgar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works like a charm :)

}
},
"status": {
"type": "string"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be nice to specify the list of allowed values here. Or would that be too restrictive?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea have done as part of next PR

@absternator absternator merged commit 0f0d2ca into main Aug 20, 2024
8 checks passed
@absternator absternator deleted the mrc-5600-status-endpoint branch August 20, 2024 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants