|
| 1 | +# soon replaced by import from rush package |
| 2 | +skip_if_no_redis = function() { |
| 3 | + testthat::skip_on_cran() |
| 4 | + |
| 5 | + if (identical(Sys.getenv("RUSH_TEST_USE_REDIS"), "true") && redux::redis_available()) { |
| 6 | + return(invisible()) |
| 7 | + } |
| 8 | + |
| 9 | + testthat::skip("Redis is not available") |
| 10 | +} |
| 11 | + |
| 12 | +redis_configuration = function() { |
| 13 | + config = redux::redis_config() |
| 14 | + r = redux::hiredis(config) |
| 15 | + r$FLUSHDB() |
| 16 | + config |
| 17 | +} |
| 18 | + |
| 19 | +start_rush = function(n_workers = 2, worker_type = "remote") { |
| 20 | + config = redis_configuration() |
| 21 | + |
| 22 | + rush::rush_plan(n_workers = n_workers) |
| 23 | + |
| 24 | + rush = if (packageVersion("rush") <= "0.4.1") { |
| 25 | + rush::rush_plan(n_workers = n_workers, worker_type = worker_type) |
| 26 | + rush::rsh(config = config) |
| 27 | + } else { |
| 28 | + rush::rush_plan(n_workers = n_workers, worker_type = worker_type) |
| 29 | + rush::rsh(config = config) |
| 30 | + } |
| 31 | + |
| 32 | + if (worker_type == "remote") { |
| 33 | + mirai::daemons(n_workers) |
| 34 | + } |
| 35 | + |
| 36 | + rush |
| 37 | +} |
| 38 | + |
| 39 | +start_rush_worker = function(n_workers = 2) { |
| 40 | + config = redis_configuration() |
| 41 | + |
| 42 | + network_id = paste(sample(LETTERS, 10), collapse = "") |
| 43 | + rush = if (packageVersion("rush") <= "0.4.1") { |
| 44 | + rush::RushWorker$new(network_id = network_id, config = config, remote = FALSE) |
| 45 | + } else { |
| 46 | + rush::RushWorker$new(network_id = network_id, config = config) |
| 47 | + } |
| 48 | + |
| 49 | + rush |
| 50 | +} |
| 51 | + |
| 52 | +# parses the string returned by rush$worker_script() and starts a processx process |
| 53 | +start_script_worker = function(script) { |
| 54 | + script = sub('^Rscript\\s+-e\\s+\\"(.*)\\"$', '\\1', script, perl = TRUE) |
| 55 | + |
| 56 | + px = processx::process$new("Rscript", |
| 57 | + args = c("-e", script), |
| 58 | + supervise = TRUE, |
| 59 | + stderr = "|", stdout = "|") |
| 60 | + px |
| 61 | +} |
0 commit comments