Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/s-fleck/joblog

Log job statuses with lgr
https://github.com/s-fleck/joblog

Last synced: about 1 month ago
JSON representation

Log job statuses with lgr

Awesome Lists containing this project

README

        

---
output: github_document
editor_options:
chunk_output_type: console
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
options(crayon.enabled = TRUE, width = 1024)
fansi::set_knit_hooks(knitr::knit_hooks)

```

# joblog

[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)

joblog proposes a format for logging the start and completion of jobs via
[lgr](https://github.com/s-fleck/lgr) (such as cron jobs or automatically
triggered etl operations) and provides utility functions to analyse such logs.
It is desinged to showcase the flexibility of lgr, and not useful on its own.

## Installation

``` r
remotes::install_github("s-fleck/joblog")
```

## Example

```{r example, width = 1000}
library(joblog)

# setup logging
lf <- paste0(tempfile(), ".jsonl")
lg <- lgr::get_logger("jobs")$set_propagate(FALSE) # prevent logging to the console
lg$add_appender(lgr::AppenderJson$new(file = lf), name = "json")

lg$list_log(job_start("example")) # log the job start
# ... do stuff ...
lg$list_log(job_finished()) # log the job end

# run the same job again
lg$list_log(job_start("example"))
lg$list_log(job_failed("something went wrong"))

# log other stuff unrelated to the job
lg$info("today is tuesday")
lg$warn("only true every 7 days")
```

Using the setup above we have logged to a json lines file that looks like this:

```{r}
lg$appenders$json$show()
```

joblog provides `scrape_joblog()` for extracting the jobs from logfile and
consolidating all info about the job from the relevant log entries, based
on the auto-generated job-id.

```{r}
scrape_joblog(lf)
```

```
#cleanup
unlink(lf)

```