Skip to main content

Exporting Parameters

In some cases users may want to export information out of the scripts running within the comet rendering process into the following workers. A typical case would be to add detail information to the payload of the error worker, in case a rendering fails due to identifiable reasons.

This can be achieved by writing a simple JSON file into the output folder of the comet_pdf process. The required file location is defined in the environment variable GRID_EXPORT_FILE. This is typically done in the main build script, e.g., /scripts/build.py.

The JSON file must contain a simple object with key and values being strings. Here is an example:

{
"cometErrorDescription": "Something weired happened...",
"cometErrorHint": "Please re-check your code..."
}

If the worker finds such a JSON file after the comet_pdf process finishes, it will interpret the content as a list of export parameters that will be added to the later jobs.

In later jobs the parameters can be used to expand placeholders in URLs, in headers, or in payloads of webhooks. Export parameters are merged with the custom parameters from the original API request. Export parameters have precedence over custom parameters.
See Webhook Variable Replacement

Restrictions​

  • Export parameter names (i.e., the JSON keys) must not be longer than 64 characters. Only alphanumeric characters and underscores are allowed. Letter case is respected.
  • Export parameter values longer than 1000 characters will be truncated.
  • A maximum of 20 parameters is allowed.

Writing export parameter file via scripting​

C-Script​

char *f = alloc(1000);
system::getenv(f, "GRID_EXPORT_FILE");
JSON test = json:alloc();
json:set_string(test, "foo", "bar");
json:write(test, f);
json:release(test);

Python​

import json
data = { "foo": "bar"}
with open( os.getenv("GRID_EXPORT_FILE"), "w") as f: json.dump(data, f)