项目作者: mrc-ide

项目描述 :
:runner::runner::runner: Lightweight Redis queues
高级语言: R
项目地址: git://github.com/mrc-ide/rrq.git
创建时间: 2016-06-01T11:32:35Z
项目社区:https://github.com/mrc-ide/rrq

开源协议:Other

下载


rrq

Project Status: WIP - Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.
R-CMD-check
codecov.io
CodeFactor

Task queues for R, implemented using Redis.

Getting started

  1. library(rrq)

Create an rrq_controller object

  1. obj <- rrq_controller("rrq:readme")
  2. rrq_default_controller_set(obj)

Submit work to the queue:

  1. t <- rrq_task_create_expr(runif(10))
  2. t
  3. #> [1] "fd08ef462c509e174338ca5920b13adf"

Query task process:

  1. rrq_task_status(t)
  2. #> [1] "PENDING"

Run tasks on workers in the background

  1. rrq_worker_spawn()
  2. #> ℹ Spawning 1 worker with prefix 'nonmetalliferous_jabiru'
  3. #> <rrq_worker_manager>
  4. #> Public:
  5. #> clone: function (deep = FALSE)
  6. #> id: nonmetalliferous_jabiru_1
  7. #> initialize: function (controller, n, logdir = NULL, name_config = "localhost",
  8. #> is_alive: function (worker_id = NULL)
  9. #> kill: function (worker_id = NULL)
  10. #> logs: function (worker_id)
  11. #> stop: function (worker_id = NULL, ...)
  12. #> wait_alive: function (timeout, time_poll = 0.2, progress = NULL)
  13. #> Private:
  14. #> check_worker_id: function (worker_id)
  15. #> controller: rrq_controller
  16. #> logfile: /tmp/Rtmp4AMYNM/filee336a6e3e1369/nonmetalliferous_jabiru_1
  17. #> process: list
  18. #> worker_id_base: nonmetalliferous_jabiru

Wait for tasks to complete

  1. rrq_task_wait(t)
  2. #> [1] TRUE

Retrieve results from a task

  1. rrq_task_result(t)
  2. #> [1] 0.044105073 0.151111529 0.047623996 0.936703515 0.719949653 0.519903127
  3. #> [7] 0.030698510 0.057218178 0.503331142 0.002863957

Query what workers have done

  1. rrq_worker_log_tail(n = Inf)
  2. #> worker_id child time command
  3. #> 1 nonmetalliferous_jabiru_1 NA 1721033895 ALIVE
  4. #> 2 nonmetalliferous_jabiru_1 NA 1721033895 ENVIR
  5. #> 3 nonmetalliferous_jabiru_1 NA 1721033895 QUEUE
  6. #> 4 nonmetalliferous_jabiru_1 NA 1721033895 TASK_START
  7. #> 5 nonmetalliferous_jabiru_1 NA 1721033895 TASK_COMPLETE
  8. #> message
  9. #> 1
  10. #> 2 new
  11. #> 3 default
  12. #> 4 fd08ef462c509e174338ca5920b13adf
  13. #> 5 fd08ef462c509e174338ca5920b13adf

For more information, see vignette("rrq")

Installation

Install from the mrc-ide R universe package repository:

  1. install.packages(
  2. "rrq",
  3. repos = c("https://mrc-ide.r-universe.dev", "https://cloud.r-project.org"))

Alternatively, install with remotes:

  1. remotes::install_github("mrc-ide/rrq", upgrade = FALSE)

Testing

To test, we need a redis server that can be automatically connected to using the redux defaults. This is satisfied if you have an unauthenticated redis server running on localhost, otherwise you should update the environment variable REDIS_URL to point at a redis server. Do not use a production server, as the package will create and delete a lot of keys.

A suitable redis server can be started using docker with

  1. ./scripts/redis start

(and stopped with ./scripts/redis stop)

Alternatively, on Windows, a native (i.e., not depending on CygWin, MSys, or WSL) port of Redis 5.0.14.1 can be installed from here, and will run out of the box.

Testing the pkgdown site with examples

The documentation includes many executed code examples. To preview the documentation with the results of these, you’ll need a Redis server running, and the rrq package installed. Then, in an R terminal:-

  1. rrq::rrq_worker$new("rrq:example")$loop()

to run a worker. Then in another R terminal,

  1. pkgdown::build_site()

and the pkgdown site will be built in the docs/ folder.

License

MIT © Imperial College of Science, Technology and Medicine