File: resetJobs.R

package info (click to toggle)
r-cran-batchtools 0.9.15%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,416 kB
  • sloc: ansic: 172; sh: 156; makefile: 2
file content (28 lines) | stat: -rw-r--r-- 1,225 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#' @title Reset the Computational State of Jobs
#'
#' @description
#' Resets the computational state of jobs in the \code{\link{Registry}}.
#' This function automatically checks if any of the jobs to reset is either pending or running.
#' However, if the implemented heuristic fails, this can lead to inconsistencies in the data base.
#' Use with care while jobs are running.
#'
#' @templateVar ids.default none
#' @template ids
#' @template reg
#' @return [\code{\link{data.table}}] of job ids which have been reset.
#'   See \code{\link{JoinTables}} for examples on working with job tables.
#' @family debug
#' @export
resetJobs = function(ids = NULL, reg = getDefaultRegistry()) {
  assertRegistry(reg, writeable = TRUE, sync = TRUE, running.ok = FALSE)
  ids = convertIds(reg, ids, default = noIds())

  info("Resetting %i jobs in DB ...", nrow(ids))
  cols = c("submitted", "started", "done", "error", "mem.used", "resource.id", "batch.id", "log.file", "job.hash")
  reg$status[ids, (cols) := list(NA_real_, NA_real_, NA_real_, NA_character_, NA_real_, NA_integer_, NA_character_, NA_character_, NA_character_), on = "job.id"]
  fns = getResultFiles(reg, ids)
  file_remove(fns)

  sweepRegistry(reg)
  invisible(ids)
}