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

connect: use the public /v1/tasks/{id} endpoint #1089

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# rsconnect (development version)

* Use the public Connect server API endpoint `/v1/tasks/{id}` to poll task
progress. (#1088)

# rsconnect 1.3.1

* Skip tests when packages "foreign" and "MASS" are not available. (#1081)
Expand Down
15 changes: 9 additions & 6 deletions R/client-connect.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,18 @@ connectClient <- function(service, authInfo) {
},

waitForTask = function(taskId, quiet = FALSE) {
start <- 0
first <- 0
wait <- 1
while (TRUE) {
path <- paste0(file.path("/tasks", taskId), "?first_status=", start)
path <- paste0(
"/v1/tasks/", taskId,
"?first=", first,
"&wait=", wait)
response <- GET(service, authInfo, path)

if (length(response$status) > 0) {
if (length(response$output) > 0) {
if (!quiet) {
messages <- unlist(response$status)
messages <- unlist(response$output)
messages <- stripConnectTimestamps(messages)

# Made headers more prominent.
Expand All @@ -119,13 +123,12 @@ connectClient <- function(service, authInfo) {
cat(paste0(messages, "\n", collapse = ""))
}

start <- response$last_status
first <- response$last
}

if (length(response$finished) > 0 && response$finished) {
return(response)
}
Sys.sleep(1)
}
},

Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-client-connect.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ test_that("waitForTask", {

task_app <- webfakes::new_app()
task_app$use(webfakes::mw_json())
task_app$get("/tasks/:id", function(req, res) {
task_app$get("/v1/tasks/:id", function(req, res) {
res$set_status(200L)$send_json(
list(
id = I(req$params$id),
user_id = I(42),
status = c(
output = c(
"2024/04/24 13:08:04.901698921 [rsc-session] Content GUID: 3bfbd98a-6d6d-41bd-a15f-cab52025742f",
"2024/04/24 13:08:04.901734307 [rsc-session] Content ID: 43888",
"2024/04/24 13:08:04.901742487 [rsc-session] Bundle ID: 94502",
Expand All @@ -52,7 +52,7 @@ test_that("waitForTask", {
finished = TRUE,
code = 0,
error = "",
last_status = 4
last = 4
), auto_unbox = TRUE
)
})
Expand Down
Loading