Skip to content

Commit c11458d

Browse files
authored
connect: use the public /v1/tasks/{id} endpoint (#1089)
fixes #1088
1 parent 5c7fcf5 commit c11458d

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# rsconnect (development version)
22

3+
* Use the public Connect server API endpoint `/v1/tasks/{id}` to poll task
4+
progress. (#1088)
5+
36
# rsconnect 1.3.1
47

58
* Skip tests when packages "foreign" and "MASS" are not available. (#1081)

R/client-connect.R

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,18 @@ connectClient <- function(service, authInfo) {
103103
},
104104

105105
waitForTask = function(taskId, quiet = FALSE) {
106-
start <- 0
106+
first <- 0
107+
wait <- 1
107108
while (TRUE) {
108-
path <- paste0(file.path("/tasks", taskId), "?first_status=", start)
109+
path <- paste0(
110+
"/v1/tasks/", taskId,
111+
"?first=", first,
112+
"&wait=", wait)
109113
response <- GET(service, authInfo, path)
110114

111-
if (length(response$status) > 0) {
115+
if (length(response$output) > 0) {
112116
if (!quiet) {
113-
messages <- unlist(response$status)
117+
messages <- unlist(response$output)
114118
messages <- stripConnectTimestamps(messages)
115119

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

122-
start <- response$last_status
126+
first <- response$last
123127
}
124128

125129
if (length(response$finished) > 0 && response$finished) {
126130
return(response)
127131
}
128-
Sys.sleep(1)
129132
}
130133
},
131134

tests/testthat/test-client-connect.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ test_that("waitForTask", {
3737

3838
task_app <- webfakes::new_app()
3939
task_app$use(webfakes::mw_json())
40-
task_app$get("/tasks/:id", function(req, res) {
40+
task_app$get("/v1/tasks/:id", function(req, res) {
4141
res$set_status(200L)$send_json(
4242
list(
4343
id = I(req$params$id),
4444
user_id = I(42),
45-
status = c(
45+
output = c(
4646
"2024/04/24 13:08:04.901698921 [rsc-session] Content GUID: 3bfbd98a-6d6d-41bd-a15f-cab52025742f",
4747
"2024/04/24 13:08:04.901734307 [rsc-session] Content ID: 43888",
4848
"2024/04/24 13:08:04.901742487 [rsc-session] Bundle ID: 94502",
@@ -52,7 +52,7 @@ test_that("waitForTask", {
5252
finished = TRUE,
5353
code = 0,
5454
error = "",
55-
last_status = 4
55+
last = 4
5656
), auto_unbox = TRUE
5757
)
5858
})

0 commit comments

Comments
 (0)