## ----setup, include = FALSE---------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment  = "#>",
  eval     = FALSE
)

## ----workflow-----------------------------------------------------------------
# library(ukbflow)
# 
# # 1. Submit extraction job
# job_id <- extract_batch(c(31, 53, 21022, 22189), file = "ukb_demographics")
# 
# # 2. Wait for completion
# job_wait(job_id)
# 
# # 3. Load result (RAP only)
# df <- job_result(job_id)

## ----job-status---------------------------------------------------------------
# job_status(job_id)
# #> job-XXXXXXXXXXXX
# #>            done

## ----job-failed---------------------------------------------------------------
# s <- job_status(job_id)
# if (s == "failed") cli::cli_inform(attr(s, "failure_message"))

## ----job-wait-----------------------------------------------------------------
# job_wait(job_id)                    # wait indefinitely (default)
# job_wait(job_id, interval = 60)     # poll every 60 seconds
# job_wait(job_id, timeout = 7200)    # give up after 2 hours

## ----job-wait-chain-----------------------------------------------------------
# job_wait(job_id)
# df <- job_result(job_id)

## ----job-path-----------------------------------------------------------------
# path <- job_path(job_id)
# #> "/mnt/project/results/ukb_demographics.csv"

## ----job-path-read------------------------------------------------------------
# df <- data.table::fread(job_path(job_id))

## ----job-result---------------------------------------------------------------
# df <- job_result(job_id)
# # returns a data.table, e.g. 502353 rows x 5 cols (incl. eid)

## ----job-ls-------------------------------------------------------------------
# job_ls()          # last 20 jobs
# job_ls(n = 5)     # last 5 jobs
# 
# # Filter by state
# job_ls(state = "failed")
# job_ls(state = c("done", "failed"))

