job: Log the start or end of a job

Description Usage Arguments Value Side Effects Examples

Description

Log the start or end (either succesfully or not) of a job. Each job has a name (for example update-prod-database). Each unique run of a job is identified by its (usually autogenerated id).

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
job_start(
  name,
  status = 1L,
  jobtype = 1L,
  ...,
  id = ulid::generate(),
  repeats = NULL,
  path = NULL,
  msg = NULL
)

job_finished(msg = NULL, id = last_job_id())

job_failed(msg = NULL, id = last_job_id())

last_job_id()

Arguments

name

character scalar. Name of the job

status

integer scalar. Status of the job; 0 = succesfully completed, 1 = started, 2 = failed.

jobtype

integer scalar. 1 = scheduled (for example via cron), 2 = triggered, 3 = manually started

...

added to the resulting list

id

a global unique id (such as UUID or ULID) for the job

repeats

timestamp when the job is expected to repeat

path

character scalar. path to the script that contains the job

msg

character scalar. a custom message to add to the job's log message

Value

job_start(), job_finsihed(), job_failed() return a list() that can be passed to Logger$list_log()

last_job_id() returns the id (a character scalar) of the last job registered with job_start().

Side Effects

job_start() assigns the variable .last_job_id to the environment joblog.globals, which is used by job_finished() and job_failed(). If you want to run several jobs concurrently, you need to pass id in manually.

Examples

1
2
3
4
5
6
7
8
9
lg <- lgr::get_logger("test")
lg$list_log(job_start("update-database"))
lg$list_log(job_finished())

# run the job again the next day
lg$list_log(job_start("update-database"))
lg$list_log(job_failed("something went wrong this time"))

last_job_id()

s-fleck/joblog documentation built on Jan. 11, 2020, 11:04 a.m.