// Hook: AfterSend // POST to a downstream HTTP API once distribution completes successfully. // // Use this to hand off to an internal workflow orchestration system: the // script signals that the ReportWORQ packet is ready to be picked up for // further processing. Failed jobs are skipped so we don't trigger work on // a known-bad output. using System.Net.Http; using System.Text; using System.Text.Json; if (!JobResult.Success) { AddWarning("Job did not complete successfully - skipping downstream trigger."); return; } const string TriggerUrl = "https://internal-api.example.com/workflows/reportworq-complete"; var body = JsonSerializer.Serialize(new { jobName = JobName, outputName = OutputName, outputFiles = JobResult.OutputFiles, completedAt = JobResult.EndTime?.ToString("O"), elapsedSeconds = JobResult.Elapsed.TotalSeconds }); // NOTE: a .csx is compiled as a *script*, where `using` at the start of a statement // is parsed as a using DIRECTIVE. `using var http = ...;` therefore does not compile. // Use the using STATEMENT form instead. using (var http = new HttpClient()) { var content = new StringContent(body, Encoding.UTF8, "application/json"); var response = await http.PostAsync(TriggerUrl, content); if (!response.IsSuccessStatusCode) AddWarning($"Downstream trigger returned HTTP {(int)response.StatusCode}."); else Logger.LogInformation($"Downstream workflow triggered successfully for '{OutputName}'."); }