Skip to content

Commit

Permalink
feat: add redis info
Browse files Browse the repository at this point in the history
  • Loading branch information
be-marc committed Feb 11, 2024
1 parent f4ce6e6 commit e0f1ada
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
15 changes: 13 additions & 2 deletions R/Rush.R
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,7 @@ Rush = R6::R6Class("Rush",
#' @return `data.table()`\cr
#' Table of finished tasks.
fetch_finished_tasks = function(fields = c("xs", "ys", "xs_extra", "worker_extra", "ys_extra"), reset_cache = FALSE, data_format = "data.table") {
lg$debug("Fetching finished tasks")
private$.fetch_cached(fields, cache = ".cached_tasks", data_format, reset_cache)
},

Expand Down Expand Up @@ -892,6 +893,8 @@ Rush = R6::R6Class("Rush",
fetch_active_tasks = function(fields = c("xs", "ys", "xs_extra", "worker_extra", "ys_extra"), data_format = "data.table") {
r = self$connector

lg$debug("Fetching active tasks")
lg$debug("Reading %i cached task(s)", length(private$.cached_tasks))

if (self$n_finished_tasks > length(private$.cached_tasks)) {

Expand All @@ -902,7 +905,7 @@ Rush = R6::R6Class("Rush",
r$LRANGE(private$.get_key("finished_tasks"), length(private$.cached_tasks), -1)
keys = r$EXEC()

lg$debug("Caching %i finished task(s)", length(keys[[3]]))
lg$debug("Caching %i new task(s)", length(keys[[3]]))

# bind new results to cached results
data_finished = set_names(self$read_hashes(keys[[3]], fields), keys[[3]])
Expand Down Expand Up @@ -1309,6 +1312,12 @@ Rush = R6::R6Class("Rush",
r = self$connector
r$command(c("CONFIG", "SET", "save", str_collapse(rhs, sep = " ")))
private$.snapshot_schedule = rhs
},

#' @field redis_info (`list()`)\cr
#' Information about the Redis server.
redis_info = function() {
redux::redis_info(self$connector)
}
),

Expand Down Expand Up @@ -1426,12 +1435,14 @@ Rush = R6::R6Class("Rush",
r = self$connector
if (reset_cache) private[[cache]] = list()

lg$debug("Reading %i cached task(s)", length(private[[cache]]))

if (self$n_finished_tasks > length(private[[cache]])) {

# get keys of new results
keys = r$command(c("LRANGE", private$.get_key("finished_tasks"), length(private[[cache]]), -1))

lg$debug("Caching %i finished task(s)", length(keys))
lg$debug("Caching %i new task(s)", length(keys))

# bind new results to cached results
data = set_names(self$read_hashes(keys, fields), keys)
Expand Down
9 changes: 9 additions & 0 deletions tests/testthat/test-Rush.R
Original file line number Diff line number Diff line change
Expand Up @@ -1026,3 +1026,12 @@ test_that("printing logs with redis appender works", {

expect_rush_reset(rush, type = "terminate")
})

test_that("redis info works", {
skip_on_cran()
skip_on_ci()

config = start_flush_redis()
rush = Rush$new(network_id = "test-rush", config = config, seed = 123)
expect_list(rush$redis_info)
})

0 comments on commit e0f1ada

Please sign in to comment.