R/q.reschedule.R

Defines functions q.reschedule

q.reschedule <- function(jid,
                         wday=NULL,
                         hour=NULL,
                         now=FALSE,
                         auto.recovery=TRUE )
  # move a specific job to  date and time
{

  do.reschedule <- function(jid.path)
  {
    if (!file.exists(jid.path))
      stop('file not found')

    TPATH = sprintf("%s/schedule/%s", .pkg.log$log.dir, basename(jid.path))

    if (file.exists(TPATH)  &&
        dirname(jid.path) != sprintf('%s/schedule', .pkg.log$log.dir))
    {
      # not scheduled job
      file.remove(TPATH)
      file.copy(from = jid.path,
                to = TPATH,
                copy.mode = TRUE)
    }

    load(TPATH)
    # update information
    if (!is.null(wday))
      ticket$wday = wday
    if (!is.null(hour))
      ticket$hour = hour

    ticket$jid = TPATH
    ticket$auto.recovery = auto.recovery

    save(ticket, file = TPATH)

    if (now)
    {
      # move to inbox to execute now
      FPATH = gsub('log/schedule', 'log/inbox', TPATH)
      file.copy(from = TPATH, to = FPATH)
    }

    return(TPATH)
  }

  if(is.vector(jid.path) )
  {
    return( bind_rows(lapply(jid,do.reschedule)) )
  } else
  {
    return ( do.reschedule(jid) )
  }

}
okux/qrmarkdown documentation built on Dec. 22, 2021, 4:17 a.m.