Skip to content

Commit 80dfdbb

Browse files
committed
aws workspace upload, download, and destroy
1 parent 768c50a commit 80dfdbb

8 files changed

+57
-12
lines changed

Diff for: DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Description: Pipeline tools coordinate the pieces of computationally
1212
The methodology in this package
1313
borrows from GNU 'Make' (2015, ISBN:978-9881443519)
1414
and 'drake' (2018, <doi:10.21105/joss.00550>).
15-
Version: 1.10.1.9000
15+
Version: 1.10.1.9001
1616
License: MIT + file LICENSE
1717
URL: https://docs.ropensci.org/targets/, https://github.com/ropensci/targets
1818
BugReports: https://github.com/ropensci/targets/issues

Diff for: NEWS.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# targets 1.10.1.9000 (development)
2-
1+
# targets 1.10.1.9001 (development)
32

3+
* Upload workspaces to the cloud if `tar_option_get("repository_meta")` is `"aws"`. Download them with `tar_workspace_download()` and delete them with `tar_destroy(destroy = "all")` or `tar_destroy(destroy = "cloud")`.
44

55
# targets 1.10.1
66

Diff for: R/class_database_aws.R

+35-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ database_aws_class <- R6::R6Class(
6969
},
7070
download_workspace = function(name, store, verbose = TRUE) {
7171
path <- path_workspace(store, name)
72-
key <- path_workspace(dirname(self$key), name)
72+
key <- path_workspace(dirname(dirname(self$key)), name)
7373
aws <- self$resources$aws
7474
if (verbose) {
7575
tar_print(
@@ -123,7 +123,7 @@ database_aws_class <- R6::R6Class(
123123
upload_workspace = function(target, meta, reporter) {
124124
name <- target_get_name(target)
125125
path <- path_workspace(meta$store, name)
126-
key <- path_workspace(dirname(self$key), name)
126+
key <- path_workspace(dirname(dirname(self$key)), name)
127127
aws <- self$resources$aws
128128
aws_s3_upload(
129129
file = path,
@@ -168,6 +168,39 @@ database_aws_class <- R6::R6Class(
168168
args = aws$args,
169169
max_tries = aws$max_tries %|||% 5L
170170
)
171+
},
172+
delete_cloud_workspaces = function() {
173+
prefix <- dirname(path_workspace(dirname(dirname(self$key)), "x"))
174+
aws <- self$resources$aws
175+
names <- names(
176+
aws_s3_list_etags(
177+
prefix = prefix,
178+
bucket = aws$bucket,
179+
page_size = 1000L,
180+
verbose = FALSE,
181+
region = aws$region,
182+
endpoint = aws$endpoint,
183+
args = aws$args,
184+
max_tries = aws$max_tries %|||% 5L,
185+
seconds_timeout = aws$seconds_timeout,
186+
close_connection = aws$close_connection,
187+
s3_force_path_style = aws$s3_force_path_style
188+
)
189+
)
190+
aws_s3_delete_objects(
191+
objects = lapply(names, function(x) list(Key = x)),
192+
bucket = aws$bucket,
193+
batch_size = 1000L,
194+
region = aws$region,
195+
endpoint = aws$endpoint,
196+
args = aws$args,
197+
max_tries = aws$max_tries %|||% 5L,
198+
seconds_timeout = aws$seconds_timeout,
199+
close_connection = aws$close_connection,
200+
s3_force_path_style = aws$s3_force_path_style,
201+
verbose = FALSE
202+
)
203+
invisible()
171204
}
172205
)
173206
)

Diff for: R/class_database_local.R

+3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ database_local_class <- R6::R6Class(
5757
tar_print("Not configured to delete cloud object ", self$key)
5858
}
5959
invisible()
60+
},
61+
delete_cloud_workspaces = function() {
62+
invisible()
6063
}
6164
)
6265
)

Diff for: R/tar_destroy.R

+6-4
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@
3333
#' @param destroy Character of length 1, what to destroy. Choices:
3434
#' * `"all"`: entire data store (default: `_targets/`)
3535
#' including cloud data, as well as download/upload scratch files.
36-
#' * `"cloud"`: cloud data, including metadata as well as target object data
37-
#' from targets with `tar_target(..., repository = "aws")`.
36+
#' * `"cloud"`: cloud data, including metadata, target object data
37+
#' from targets with `tar_target(..., repository = "aws")`,
38+
#' and workspace files saved on the cloud.
3839
#' Also deletes temporary staging files in
3940
#' `file.path(tempdir(), "targets")`
4041
#' that may have been accidentally left over from incomplete
@@ -135,7 +136,7 @@ tar_destroy <- function(
135136
batch_size = batch_size,
136137
verbose = verbose
137138
)
138-
tar_delete_cloud_meta(script = script)
139+
tar_delete_cloud_meta_and_workspaces(script = script)
139140
unlink(path_scratch_dir_network(), recursive = TRUE)
140141
}
141142
if (tar_should_delete(path = path, ask = ask)) {
@@ -146,7 +147,7 @@ tar_destroy <- function(
146147

147148
# Covered in AWS and GCP tests.
148149
# nocov start
149-
tar_delete_cloud_meta <- function(script) {
150+
tar_delete_cloud_meta_and_workspaces <- function(script) {
150151
if (!file.exists(script)) {
151152
return()
152153
}
@@ -167,6 +168,7 @@ tar_delete_cloud_meta <- function(script) {
167168
progress$delete_cloud(verbose = FALSE)
168169
process$delete_cloud(verbose = FALSE)
169170
crew$delete_cloud(verbose = FALSE)
171+
meta$delete_cloud_workspaces()
170172
invisible()
171173
}
172174
# nocov end

Diff for: man/tar_destroy.Rd

+3-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: tests/aws/test-aws-workspaces.R

+6-1
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,17 @@ tar_test("aws workspaces are uploaded and downloaded", {
2626
})
2727
expr <- tar_tidy_eval(expr, environment(), TRUE)
2828
eval(as.call(list(`tar_script`, expr, ask = FALSE)))
29-
expect_error(tar_make(callr_function = NULL), class = "tar_condition_run")
3029
path <- "_targets/workspaces/x"
30+
expect_false(aws_s3_exists(key = path, bucket = bucket_name))
31+
expect_error(tar_make(callr_function = NULL), class = "tar_condition_run")
32+
expect_true(aws_s3_exists(key = path, bucket = bucket_name))
3133
unlink(path)
3234
expect_false(file.exists(path))
3335
expect_error(tar_workspace(x), class = "tar_condition_validate")
3436
tar_workspace_download(x)
3537
expect_true(file.exists(path))
3638
expect_silent(tar_workspace(x))
39+
tar_destroy()
40+
expect_false(aws_s3_exists(key = path, bucket = bucket_name))
41+
expect_error(tar_workspace_download(x), class = "http_404")
3742
})

Diff for: tests/testthat/test-class_database.R

+1
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ tar_test("local database cloud methods", {
426426
expect_null(database$download_workspace(NULL, NULL, TRUE))
427427
expect_null(database$upload())
428428
expect_null(database$upload_workspace(NULL, NULL, TRUE))
429+
expect_null(database$delete_cloud_workspaces())
429430
expect_false(database$head()$exists)
430431
expect_null(database$delete_cloud())
431432
})

0 commit comments

Comments
 (0)