Skip to content

Commit

Permalink
Added reindexVersion function for the latest gobbler API.
Browse files Browse the repository at this point in the history
  • Loading branch information
LTLA committed Jan 28, 2025
1 parent 787f959 commit 79d8878
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 4 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: gobbler
Version: 0.3.10
Date: 2024-10-18
Version: 0.3.11
Date: 2025-01-28
Title: Interface to the gobbler service
Description:
Friendly interface to the gobbler service.
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export(listProjects)
export(listVersions)
export(refreshLatest)
export(refreshUsage)
export(reindexVersion)
export(rejectProbation)
export(removeAsset)
export(removeProject)
Expand Down
37 changes: 37 additions & 0 deletions R/reindexVersion.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#' Reindex a versioned asset
#'
#' Reindex a version of an asset of a project from the registry.
#' This regenerates all of the internal \code{..manifest} and \code{..links} files.
#'
#' @param project String containing the project to remove.
#' @param asset String containing the asset to remove.
#' @param version String containing the version of the asset to remove.
#' @inheritParams createProject
#'
#' @return \code{NULL} is invisibly returned if the version was successfully reindexed.
#'
#' @author Aaron Lun
#'
#' @examples
#' info <- startGobbler()
#' removeProject("test", info$staging, url=info$url) # start with a clean slate.
#' createProject("test", info$staging, url=info$url)
#'
#' # Mocking up a version if it doesn't already exist.
#' src <- allocateUploadDirectory(info$staging)
#' write(file=file.path(src, "foo"), "BAR")
#' uploadDirectory("test", "simple", "v1", src, staging=info$staging, url=info$url)
#' fetchManifest("test", "simple", "v1", registry=info$registry, url=info$url)
#'
#' # Let's add a new file directly to the directory.
#' write(file=file.path(info$registry, "test", "simple", "v1", "whee"), "stuff")
#'
#' # And reindexing the version.
#' reindexVersion("test", "simple", "v1", staging=info$staging, url=info$url)
#' fetchManifest("test", "simple", "v1", registry=info$registry, url=info$url)
#'
#' @export
reindexVersion <- function(project, asset, version, staging, url) {
dump_request(staging, url, "reindex_version", list(project=project, asset=asset, version=version))
invisible(NULL)
}
2 changes: 1 addition & 1 deletion R/startGobbler.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#'
#' @export
#' @importFrom utils download.file
startGobbler <- function(staging=tempfile(), registry=tempfile(), port = NULL, wait = 1, version = "0.3.7", overwrite = FALSE) {
startGobbler <- function(staging=tempfile(), registry=tempfile(), port = NULL, wait = 1, version = "0.3.8", overwrite = FALSE) {
if (!is.null(running$active)) {
return(list(new=FALSE, staging=running$staging, registry=running$registry, port=running$port, url=assemble_url(running$port)))
}
Expand Down
48 changes: 48 additions & 0 deletions man/reindexVersion.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/startGobbler.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions tests/testthat/test-reindexVersion.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# library(testthat); library(gobbler); source("test-reindexVersion.R")

info <- startGobbler()
removeProject("test-R-reindex", staging=info$staging, url=info$url)
createProject("test-R-reindex", staging=info$staging, url=info$url)

test_that("reindexing functions work as expected", {
src <- allocateUploadDirectory(info$staging)
write(file=file.path(src, "foo"), "BAR")
uploadDirectory("test-R-reindex", "simple", "v1", src, staging=info$staging, url=info$url)

# Let's add a new file directly to the directory.
write(file=file.path(info$registry, "test-R-reindex", "simple", "v1", "whee"), "stuff")

# This does not show up in the manifest...
man <- fetchManifest("test-R-reindex", "simple", "v1", registry=info$registry, url=info$url)
expect_identical(names(man), "foo")

# Until we reindex the version.
reindexVersion("test-R-reindex", "simple", "v1", staging=info$staging, url=info$url)
man <- fetchManifest("test-R-reindex", "simple", "v1", registry=info$registry, url=info$url)
expect_identical(names(man), c("foo", "whee"))
})

0 comments on commit 79d8878

Please sign in to comment.