-
Notifications
You must be signed in to change notification settings - Fork 0
/
rs_delete.R
74 lines (66 loc) · 1.58 KB
/
rs_delete.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#' Delete AppEEARS task from queue
#'
#' Removes a task from the queue and or buffer
#'
#' @param user username used to sign up
#' @param task_id AppEEARS task id
#' @param purge if TRUE, remove all previously finished tasks from
#' the task list (default = FALSE)
#' @return returns the content of the API call
#'
#' @export
#' @author Koen Hufkens
#' @examples
#'
#' \dontrun{
#' # delete a single task
#' rs_delete(
#' user = "your_user_name",
#' task_id = "a_task_id"
#' )
#'
#' # delete all finished or crashed
#' # jobs (if not deleted previously)
#' rs_delete(
#' user = "your_user_name",
#' purge = TRUE
#' )
#'}
rs_delete <- function(
task_id,
user,
purge = FALSE
){
# check if task_id is present
if (isFALSE(purge) && missing(task_id)) {
stop("Missing task id to delete!")
}
# retrieve token to list tasks
token <- appeears::rs_login(user)
# if purge is set to TRUE, list
# all task_ids which are done or are crashed
# keep running processes untouched
if (purge) {
task_list <- rs_list_task(user = user)
task_id <-
task_list$task_id[which(task_list$status == "done" | task_list$crashed)]
}
lapply(task_id, function(id){
response <- httr::DELETE(
file.path(rs_server(),"task", id),
httr::add_headers(
Authorization = paste("Bearer", token)
)
)
# trap general http error
if (httr::http_error(response)) {
stop(
"Your task %s failed to delete.\n
It was either previously delete or a wrong task id was provided.",
call. = FALSE
)
}
})
# return empty
return(invisible())
}