Skip to content

Make gateaux_job_runner more robust #5

Description

@yvanrichard

The current construction of the curl command does not escape nested quotes.
The httr::POST function deals with it nicely. The list of parameters can be passed as it is without needing to care about quotes.


params <- list(
  TAG          = "QMA2.Formula:FisherExperience",
  ITER         = "200",
  WARMUP       = "300",
  YEAR         = "2025",
  FY_FACT      = "ClientNumber",
  PCELR_BY_DAY = "TRUE",
  CLASS        = "FALSE",
  OFFSET       = "TRUE",
  CATCH        = "FALSE",
  FS_REGIONS   = "TRUE",
  COREAREA     = "5",
  DIVERYR      = "5",
  CLIENTYR     = "5",
  FSTRING      = "
    bf(log(GreenweightKgQuantity/nSA) | weights(1/nSA) ~ LP + NLP, nl=T) +
    lf(LP ~ (1 | ClientNumber) + RS + (1 | FishingYear) + (1 | RS:FishingYear) + (1 | CatcherId) + lFD +  (1 | StatisticalAreaCode)) +
    nlf(NLP ~ log(((inv_logit(a*FY))-0.5)*2)) + lf(a~1)
    ",
  QMA          = "2",
  PSTRING      = "
    set_prior('normal(0,5)', class = 'sd', nlpar = 'LP') +
    set_prior('normal(0,5)', class = 'sigma') +
    set_prior('normal(3.5,10)', coef = 'Intercept', nlpar = 'LP') +
    set_prior('normal(0,5)', class = 'b', nlpar = 'LP') +
    set_prior('lognormal(0, 2)', nlpar = 'a')
    "
)

response <- httr::POST(
  url = "https://kahawai.io/job/PAU-CPUE-STD-SM",
  httr::add_headers(Authorization = sprintf('Bearer %s', JWT),
                   "Content-Type" = "application/json"),
  body = list(env = params),
  encode = "json"
)

if (httr::http_error(response)) {
  stop("Job triggering failed: ", httr::http_status(response)$reason)
} else {
  message("Job triggered successfully!")
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions