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 5114 Add a submit function to the queue object #5

Merged
merged 38 commits into from
Aug 1, 2024
Merged

Conversation

M-Kusumgar
Copy link
Contributor

@M-Kusumgar M-Kusumgar commented Mar 7, 2024

Finally got a PR up for this! This adds the submit function to the queue and returns the task_id from rrq. The strategy for the worker dirs was that we were going to git clone the orderly root and fetch before we run a report. We can then checkout and hard reset on to the desired commit.

This PR also required mrc-ide/rrq#110 and mrc-ide/orderly2#130 for the env vars required to make this work

@M-Kusumgar M-Kusumgar changed the title Mrc 5114 Mrc 5114 Add a submit function to the queue object Mar 7, 2024
R/runner.R Outdated
@@ -0,0 +1,59 @@
runner_run <- function(orderly_root, reportname, parameters, branch, ref, ...) {
# Helper functions
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are here because there is a bug in rrq_task_create_call and it doesn't seem to capture them. Made a ticket about this: https://mrc-ide.myjetbrains.com/youtrack/issue/mrc-5153/Investigate-rrqtaskcreatecall-bug

Copy link
Contributor

Choose a reason for hiding this comment

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

Does this work if you call rrq::rrq_task_create_call with the package qualifier? i.e. as orderly.runner:::runner_run?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i tried it, didnt seem to even pick up orderly:::runner_run like the task completed successfully but it didnt do anything

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ohhh nevermind, i didnt install it, it did work!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it actually works without it too, i just didnt do an install all and so it didnt pick it up from the orderly.runner package 😭 i was avoiding that cos I was relying on specific branches of the orderly2 and rrq repos and didnt know if install all would overwrite them with the head of the github repo, but yh that was the issue!

@M-Kusumgar M-Kusumgar requested review from richfitz and r-ash March 7, 2024 17:42
Copy link
Contributor

@r-ash r-ash left a comment

Choose a reason for hiding this comment

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

This looks great, couple of questions/comments. I wonder if your helper functions will be available if you call your rrq submit with the package qualified name.

Is the plan to expose this in the API the next PR?

Comment on lines 69 to 71
q <- new_queue_quietly(root)
worker_manager <- start_queue_workers_quietly(1, q$controller)
make_worker_dirs(root, worker_manager$id)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could wrap this in a helper to get a queue with specified number of workers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Comment on lines 118 to 126
for (i in seq_len(n_tries)) {
is_completed <- rrq::rrq_task_status(
task_id, controller = controller
) == "COMPLETE"
if (is_completed == TRUE) {
break
}
Sys.sleep(1)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

You can use rrq_task_wait for this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ooo thats neat thanks

R/runner.R Outdated
@@ -0,0 +1,59 @@
runner_run <- function(orderly_root, reportname, parameters, branch, ref, ...) {
# Helper functions
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this work if you call rrq::rrq_task_create_call with the package qualifier? i.e. as orderly.runner:::runner_run?

Comment on lines +57 to +58
# Cleanup
git_clean(worker_path)
Copy link
Contributor

Choose a reason for hiding this comment

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

In what case do we need to cleanup?

Just tried locally and I was able to use point_head_to_ref to switch between commits without cleaning up anything in between.

Is this for if orderly fails to run and writes to the draft dir? I think that will be gitignored?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

at the end of a successful run, orderly deletes the file from the draft folder and leaves an empty folder in the directory, the most important bit of this git clean function is the removing of those empty dirs, just to keep a clean worktree after every run, otherwise that draft folder would just keep accumulating lots of empty folders after many runs

the stash and drop is just a safety in case someone has somehow produced something that is untracked by git, we can guarantee that it is removed and doesnt accumulate, people could also change their gitignore files which could also lead to these problems i think

Copy link
Member

Choose a reason for hiding this comment

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

I wonder if it might also be worth (or worth doing in addition) the clean before running the report?

Copy link

codecov bot commented Mar 8, 2024

Codecov Report

Attention: Patch coverage is 97.29730% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 99.44%. Comparing base (0c8dfbd) to head (b69faac).

❗ Current head b69faac differs from pull request most recent head 7f8f52f. Consider uploading reports for the commit 7f8f52f to get more accurate results

Files Patch % Lines
R/runner.R 96.42% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##              main       #5      +/-   ##
===========================================
- Coverage   100.00%   99.44%   -0.56%     
===========================================
  Files            7        8       +1     
  Lines          142      179      +37     
===========================================
+ Hits           142      178      +36     
- Misses           0        1       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@M-Kusumgar
Copy link
Contributor Author

Is the plan to expose this in the API the next PR?

yh i wanted to get this object sorted, once the status and submit are in, adding the endpoints should hopefully be a fairly easy PR

Copy link
Member

@richfitz richfitz left a comment

Choose a reason for hiding this comment

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

I didn't get a chance to run this up, sorry. But the implementation looks great, much simpler than orderly1 I think. I'm sure when we use it in practice we'll iterate a few times getting the git stuff right, but this feels at least on the right not track, possibly it'll be all we need

orderly2::orderly_artefact("Some data", "data.rds")
d <- data.frame(a = 1:10, x = runif(10), y = 1:10 + runif(10))
write.table("test", file = file.path("..", "..", "inside_draft.txt"))
write.table("test", file = file.path("..", "..", "..", "outside_draft.txt"))
Copy link
Member

Choose a reason for hiding this comment

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

naughty!

Comment on lines +57 to +58
# Cleanup
git_clean(worker_path)
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if it might also be worth (or worth doing in addition) the clean before running the report?

@r-ash
Copy link
Contributor

r-ash commented May 3, 2024

Pushed a commit here which will

  • Update to use latest rrq (mostly dropping the 2 from the end of a couple of functions)
  • Make the tests work with any configured default git branch, these were failing for me as I have my config set to initialise as "main" by default

@M-Kusumgar M-Kusumgar merged commit e15473b into main Aug 1, 2024
7 checks passed
@M-Kusumgar M-Kusumgar mentioned this pull request Aug 2, 2024
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.

3 participants