R/Job.R

Defines functions print.Job getJobIds getJobNr makeJob

Documented in getJobIds getJobNr makeJob

#' Creates a job description.
#'
#' Usually you will not do this manually.
#' Every object is a list that contains the passed arguments of the constructor.
#'
#' @param id [\code{integer(1)}]\cr
#'   Job id, determined by DB autoincrement.
#'   Default is \code{NA}.
#' @param fun [\code{function}]\cr
#'   Job function to apply on parameters.
#' @param fun.id [\code{character(1)}]\cr
#'   Id used to store function on disk.
#'   Default is \code{digest(fun)}.
#' @param pars [\code{list}]\cr
#'   Parameter list for job function.
#' @param name [\code{character(1)}]\cr
#'   Alias name for this job.
#' @param seed [\code{integer(1)}]\cr
#'   Random seed for job.
#' @aliases Job
#' @export
makeJob = function(id = NA_integer_, fun, fun.id = digest(fun), pars, name, seed) {
  setClasses(list(id = id, fun = fun, fun.id = fun.id, pars = pars, name = name, seed = seed), "Job")
}

#' Get number of jobs in registry.
#' @template arg_reg
#' @return [\code{integer(1)}].
#' @export
getJobNr = function(reg) {
  checkRegistry(reg, writeable = FALSE)
  dbGetJobCount(reg)
}

#' Get ids of jobs in registry.
#' @template arg_reg
#' @return [\code{character}].
#' @export
getJobIds = function(reg) {
  checkRegistry(reg, writeable = FALSE)
  dbGetJobIds(reg)
}

#' @export
print.Job = function(x, ...) {
  cat("BatchJobs job:\n")
  catf("  Job id: %s", x$id)
  catf("  Fun id: %s", x$fun.id)
  if (!is.null(x$fun) && is.function(x$fun))
    catf("  Fun formals: %s", collapse(names(formals(x$fun))))
  catf("  Name: %s", x$name)
  catf("  Seed: %i", x$seed)
  catf("  Pars: %s", convertToShortString(x$pars))
}

Try the BatchJobs package in your browser

Any scripts or data that you put into this service are public.

BatchJobs documentation built on March 21, 2022, 5:05 p.m.