Skip to content

Commit

Permalink
connect: use the public /v1/tasks/{id} endpoint (#1089)
Browse files Browse the repository at this point in the history
fixes #1088
  • Loading branch information
aronatkins authored Jul 3, 2024
1 parent 5c7fcf5 commit c11458d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
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

0 comments on commit c11458d

Please sign in to comment.