Skip to content

Commit

Permalink
started working on queueing #2
Browse files Browse the repository at this point in the history
  • Loading branch information
sckott committed May 20, 2020
1 parent 76eefde commit 11d9fe3
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
6 changes: 4 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ License: MIT + file LICENSE
URL: https://docs.ropensci.org/mutant, https://github.com/ropensci/mutant
BugReports: https://github.com/ropensci/mutant/issues
LazyData: true
Roxygen: list(markdown = TRUE)
Roxygen: list(markdown=TRUE)
Encoding: UTF-8
Imports:
pkgapi,
Expand All @@ -20,6 +20,8 @@ Imports:
astr,
withr,
R6,
pkgload
pkgload,
liteq,
rappdirs
RoxygenNote: 7.1.0
Remotes: r-lib/pkgapi, ropenscilabs/astr
55 changes: 55 additions & 0 deletions R/queue.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#' mutant queue
#' @importFrom liteq xxx
#' @importFrom rappdirs user_cache_dir
#' @param x x
#' @param x x
queue <- function(temporary = TRUE) {
assert(temporary, "logical")
if (temporary) db_path <- tempfile()
if (!temporary) {
db_path <- file.path(rappdirs::user_data_dir("R/mutant"),
basename(tempfile()))
}
q <- liteq::ensure_queue("jobs", db = db_path)

}

queue <- R6::R6Class(
'queue',
public = list(
q = NULL,
#' @description print method for `queue` objects
#' @param x self
#' @param ... ignored
print = function(x, ...) {
cat("<queue> ", sep = "\n")
for (i in seq_along(self$muts)) {
cat(paste0(" mutant name: ", self$muts[[i]]$name), sep = "\n")
}
invisible(self)
},

#' @description Create a new queue object
#' @return A new `queue` object
initialize = function(temporary = TRUE) {
assert(temporary, "logical")
if (temporary) db_path <- tempfile()
if (!temporary) {
db_path <- file.path(rappdirs::user_data_dir("R/mutant"),
basename(tempfile()))
}
self$q <- liteq::ensure_queue("jobs", db = db_path)
return(self)
},

publish = function(title, message) {
liteq::publish(self$q, title = title, message = message)
},

consume = function() {
liteq::try_consume(self$q)
}
),
private = list()
)

0 comments on commit 11d9fe3

Please sign in to comment.