File: sweepRegistry.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 (68 lines) | stat: -rw-r--r-- 2,212 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#' @title Check Consistency and Remove Obsolete Information
#'
#' @description
#' Canceled jobs and jobs submitted multiple times may leave stray files behind.
#' This function checks the registry for consistency and removes obsolete files
#' and redundant data base entries.
#'
#' @template reg
#' @family Registry
#' @export
sweepRegistry = function(reg = getDefaultRegistry()) {
  assertRegistry(reg, writeable = TRUE, sync = TRUE, running.ok = FALSE)
  "!DEBUG [sweepRegistry]: Running sweepRegistry"

  submitted = reg$status[.findSubmitted(reg = reg), c("job.id", "job.hash")]
  obsolete = chsetdiff(
    list.files(dir(reg, "results"), full.names = TRUE),
    getResultFiles(reg, submitted)
  )
  if (length(obsolete)) {
    info("Removing %i obsolete result files ...", length(obsolete))
    fs::file_delete(obsolete)
  }

  obsolete = chsetdiff(
    list.files(dir(reg, "logs"), full.names = TRUE),
    getLogFiles(reg, submitted)
  )
  if (length(obsolete)) {
    info("Removing %i obsolete log files ...", length(obsolete))
    fs::file_delete(obsolete)
  }

  obsolete = list.files(dir(reg, "jobs"), pattern = "\\.rds", full.names = TRUE)
  if (length(obsolete)) {
    info("Removing %i obsolete job collection files ...", length(obsolete))
    fs::file_delete(obsolete)
  }

  obsolete = list.files(dir(reg, "jobs"), pattern = "\\.job$", full.names = TRUE)
  if (length(obsolete)) {
    info("Removing %i job description files ...", length(obsolete))
    fs::file_delete(obsolete)
  }

  obsolete = chsetdiff(
    list.files(dir(reg, "external"), pattern = "^[0-9]+$", full.names = TRUE),
    getExternalDirs(reg, submitted)
  )
  if (length(obsolete)) {
    info("Removing %i external directories of unsubmitted jobs ...", length(obsolete))
    fs::dir_delete(obsolete)
  }

  obsolete = reg$resources[!reg$status, on = "resource.id", which = TRUE]
  if (length(obsolete)) {
    info("Removing %i resource specifications ...", length(obsolete))
    reg$resources = reg$resources[-obsolete]
  }

  obsolete = reg$tags[!reg$status, on = "job.id", which = TRUE]
  if (length(obsolete)) {
    info("Removing %i tags ...", length(obsolete))
    reg$tags = reg$tags[-obsolete]
  }

  saveRegistry(reg)
}