DHI.Services.Jobs.Executer — Internal Developer Guide¶
This utility posts a Job to a DHI Jobs API using bearer auth and a resilient HTTP policy. Ship it with CI/CD, operators, or other services when you need to enqueue work from scripts or containers.
What it does¶
- Parses CLI arguments (supports
-,--,/,:,=and quotes) - Fetches a bearer token from
<urlAuth>/api/tokens - POSTs the job to
<url>/api/jobs/{connectionId}with a JSON body:
{
"taskId": "My.Task.Id",
"hostGroup": "prod",
"priority": 1,
"tag": "my-run",
"parameters": { "Key": "Value" }
}
- Optionally writes the HTTP response JSON to a file
- Exits 0 on success, 1 otherwise
Installing¶
dotnet add package DHI.Services.Jobs.Executer
Place an appsettings.json next to the executable (see below) or rely on the defaults.
Command line¶
Required¶
-taskId <id>— the job’s task id-connectionId <id>— the server-side connection id-url <https://host:port/>— base URL for the Jobs API (trailing/okay; tool adds one)-username <user>-password <pass>-parametersFileName <path>— JSON file with job parameters (see “Parameters”)
Warning
Current behavior: -parametersFileName is required even if you also pass -parameters. If you want to use only -parameters, provide a small empty JSON file (e.g., {}) and point -parametersFileName at it. (The help text says “ignored,” but the code throws if the file is missing.)
Strongly recommended¶
-urlAuth <https://auth-host:port/>— base URL for auth; if auth shares the same base as-url, pass the same URL here. (The tool attempts to call<urlAuth>api/tokens.)
Optional¶
-hostGroup <name>— force execution on a host group-priority <int>— lower is higher priority (e.g.,1)-tag <text>— annotate the job-parameters "<k1>:<v1>;<k2>:<v2>"— quick overrides (see note above)-responseFileName <path>— save the JSON API response
Examples¶
Windows (PowerShell)
.\DHI.Services.Jobs.Executer.exe `
-username $env:JOB_USER `
-password $env:JOB_PASS `
-url https://jobs.example.local/ `
-urlAuth https://auth.example.local/ `
-connectionId wf-job `
-taskId My.Workflow.Run `
-hostGroup prod `
-priority 1 `
-tag nightly `
-parametersFileName params.json `
-parameters "Region:EU;DryRun:false" `
-responseFileName last-response.json
Linux / macOS (bash)
./DHI.Services.Jobs.Executer \
-username "$JOB_USER" \
-password "$JOB_PASS" \
-url https://jobs.example.local/ \
-urlAuth https://auth.example.local/ \
-connectionId wf-job \
-taskId My.Workflow.Run \
-hostGroup prod \
-priority 1 \
-tag nightly \
-parametersFileName params.json
Parameters¶
-
-parametersFileNamepoints to a JSON file that deserializes intoDictionary<string, object>, e.g.:{ "InputPath": "/data/in", "OutputPath": "/data/out", "Iterations": 3, "Verbose": true } -
-parameters(inline) supplieskey:valuepairs separated by;. Values are strings; the tool will send them as strings unless the file already set a typed value.
Merge rule: File is read first. If
-parametersis also provided, the inline replaces the entire set (not a merge).
Authentication¶
-
The tool POSTs to
POST <urlAuth>api/tokenswith:{ "Id": "<username>", "Password": "<password>" } -
It expects a response shaped like:
{ "accessToken": { "token": "<jwt>" } } -
The token is then used as
Authorization: Bearer <token>for the Jobs API POST.
VariablesOverride.json¶
If present in the working directory, this file overrides CLI credentials:
{
"AuthUserName": "ci-bot",
"AuthPassword": "s3cr3t",
"UrlAuth": "https://auth.example.local/"
}
Keys:
AuthUserName→ overrides-usernameAuthPassword→ overrides-passwordUrlAuth→ overrides-urlAuth
Resilience & logging¶
HTTP retry policy¶
- Retries: 5
- Triggers on:
HttpRequestException,TaskCanceledException, or any non-2xx response - Backoff: jittered exponential, roughly
Random(50..500ms) * 2^retry - Fallback: after retries, returns a synthetic 403 with text message (so callers can handle uniformly)
Logging¶
-
Configured via
appsettings.jsonin the executable folder:{ "LoggerType": "DHI.Services.Notifications.SimpleLogger, DHI.Services", "LoggerConnectionString": "[Path]DHI.Services.Jobs.Executer.log" } -
[Path]is replaced with the executable folder. IfLoggerTypecannot be created, it falls back toSimpleLogger.
Exit codes¶
0— job successfully posted (2xx response)1— any failure (missing args, auth failure, non-2xx after retries, exceptions)
Notes¶
- Always supply
-urlAuth(even if same as-url) to avoid relative-URL issues when fetching tokens. - The command-line parser is flexible with
-,--,/and quoting (e.g.,-tag "a b"or-tag:'a b'). - If you must run with no parameters, create an empty file
{}and pass its path to-parametersFileName.
Programmatic use¶
If you embed parts of the package:
JobDtois the serialized body.-
HttpFailureRetryPolicywraps anHttpClientcall:var retry = new HttpFailureRetryPolicy(logger); var rsp = await retry.ExecuteAsync(() => client.PostAsync(url, content)); -
CommandLineParsermaps args like-k v,--k=v,/k:"v"to a case-insensitive dictionary (this["k"]).