id: dagster-job-run-compliance-gate
namespace: company.team
description: |
Trigger a Dagster job, wait for it to reach a terminal state, classify
the result as HEALTHY (SUCCESS), AT_RISK (FAILURE, CANCELED, or any
other non-success terminal state), or UNREACHABLE (the GraphQL call
itself failed), alert Slack, and conditionally launch one fresh retry
run. auto_remediate and dry_run are two independent gates; the original
failed run is never altered or deleted - only a brand new run may start.
inputs:
- id: job_name
type: STRING
displayName: "Dagster Job Name"
defaults: "example_job"
description: Dagster job audited, matching this plugin's own documented jobName
property (see dagster-trigger-job.yaml).
- id: repository
type: STRING
displayName: "Dagster Repository Name"
description: Repository containing job_name.
- id: location
type: STRING
displayName: "Dagster Code Location Name"
description: Code location containing repository.
- id: max_wait_duration
type: STRING
displayName: "Max Wait Duration"
defaults: "PT30M"
description: Ceiling this flow waits for the run to reach a terminal state,
matching the maxDuration property documented on TriggerRun.
- id: auto_remediate
type: SELECT
displayName: "Auto Remediate"
defaults: "false"
values:
- "false"
- "true"
description: If "true" and the run is AT_RISK, launch one fresh retry run of
job_name (still gated by dry_run below). If "false", the risk is only
reported.
- id: dry_run
type: SELECT
displayName: "Dry Run"
defaults: "true"
values:
- "true"
- "false"
description: If "true", remediation is only logged, no retry run is launched.
Must be explicitly "false", together with auto_remediate "true", for a
fresh run to actually start.
triggers:
- id: periodic_job_compliance_check
type: io.kestra.plugin.core.trigger.Schedule
description: "Run and audit the job every 6 hours. Shipped disabled; enable it
once job_name/repository/location point at a real Dagster job and a manual
run has been verified. Always fires in safe mode (auto_remediate false,
dry_run true) regardless of this flow's own defaults."
cron: "0 */6 * * *"
disabled: true
inputs:
job_name: "example_job"
max_wait_duration: "PT30M"
auto_remediate: "false"
dry_run: "true"
repository: replace-with-your-repository
location: replace-with-your-location
tasks:
- id: trigger_and_wait_job_run
type: io.kestra.plugin.dagster.TriggerRun
description: "Launches job_name over the Dagster GraphQL API and, with wait
true, blocks until it reaches a terminal state, returning status -
documented as QUEUED, STARTING, STARTED, SUCCESS, FAILURE, or CANCELED.
allowFailure true (a base Task property) lets a GraphQL connection failure
be classified as UNREACHABLE by the next task instead of failing this
execution outright."
baseUrl: "{{ secret('DAGSTER_BASE_URL') }}"
jobName: "{{ inputs.job_name }}"
repository: "{{ inputs.repository }}"
location: "{{ inputs.location }}"
wait: true
maxDuration: "{{ inputs.max_wait_duration }}"
options:
headers:
Authorization: "Bearer {{ secret('DAGSTER_TOKEN') }}"
allowFailure: true
- id: classify_run_outcome
type: io.kestra.plugin.core.debug.Return
description: "Classify UNREACHABLE when status is not defined (the GraphQL call
itself failed), AT_RISK when the run reached a terminal state other than
SUCCESS, otherwise HEALTHY."
format: "{{ outputs.trigger_and_wait_job_run.status is defined ?
(outputs.trigger_and_wait_job_run.status == 'SUCCESS' ? 'HEALTHY' :
'AT_RISK') : 'UNREACHABLE' }}"
- id: route_by_outcome
type: io.kestra.plugin.core.flow.Switch
description: "Log a quiet confirmation when healthy, route to the remediation
gate when the run failed or was canceled, or page Slack when the Dagster
API itself could not be reached."
value: "{{ outputs.classify_run_outcome.value }}"
cases:
"HEALTHY":
- id: log_healthy
type: io.kestra.plugin.core.log.Log
message: "{{ inputs.job_name }} (run {{ outputs.trigger_and_wait_job_run.runId
}}) completed with status SUCCESS."
"AT_RISK":
- id: route_remediation
type: io.kestra.plugin.core.flow.Switch
description: "auto_remediate only decides whether remediation is considered at
all; dry_run, checked separately below, decides whether a fresh run
is actually launched."
value: "{{ inputs.auto_remediate }}"
cases:
"true":
- id: check_dry_run
type: io.kestra.plugin.core.flow.If
condition: "{{ inputs.dry_run == \"false\" }}"
then:
- id: retrigger_job_run
type: io.kestra.plugin.dagster.TriggerRun
description: "Launches a brand new run of job_name. wait false so this flow does
not block a second time waiting on the retry; the next
scheduled audit (or a manual run) observes the retry's own
outcome. The original failed run
(outputs.trigger_and_wait_job_run.runId) is never
cancelled, altered, or re-run in place."
baseUrl: "{{ secret('DAGSTER_BASE_URL') }}"
jobName: "{{ inputs.job_name }}"
repository: "{{ inputs.repository }}"
location: "{{ inputs.location }}"
wait: false
options:
headers:
Authorization: "Bearer {{ secret('DAGSTER_TOKEN') }}"
allowFailure: true
- id: log_remediation_applied
type: io.kestra.plugin.core.log.Log
message: "Launched a fresh retry run of {{ inputs.job_name }} (new run {{
outputs.retrigger_job_run.runId }}) after run {{
outputs.trigger_and_wait_job_run.runId }} came back {{
outputs.trigger_and_wait_job_run.status }}."
else:
- id: log_dry_run_remediation
type: io.kestra.plugin.core.log.Log
message: "DRY RUN: would launch a fresh retry run of {{ inputs.job_name }} after
run {{ outputs.trigger_and_wait_job_run.runId }} came back
{{ outputs.trigger_and_wait_job_run.status }} (dry_run is
true). No run launched."
"false":
- id: log_remediation_disabled
type: io.kestra.plugin.core.log.Log
message: "auto_remediate is false: run {{ outputs.trigger_and_wait_job_run.runId
}} of {{ inputs.job_name }} came back {{
outputs.trigger_and_wait_job_run.status }}, but no retry was
launched."
- id: alert_at_risk
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: "Always alert on AT_RISK, independent of whether a retry was
launched."
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{
"text": "Dagster job run compliance gate AT_RISK: run {{ outputs.trigger_and_wait_job_run.runId }} of {{ inputs.job_name }} came back {{ outputs.trigger_and_wait_job_run.status }}. auto_remediate: {{ inputs.auto_remediate }}. dry_run: {{ inputs.dry_run }}. Execution {{ execution.id }}."
}
"UNREACHABLE":
- id: alert_unreachable
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{
"text": "Dagster job run compliance gate UNREACHABLE: the TriggerRun call against {{ secret('DAGSTER_BASE_URL') }} for {{ inputs.job_name }} did not return a status (GraphQL connection failure or invalid job/repository/location). Execution {{ execution.id }}."
}
defaults:
- id: log_unclassified
type: io.kestra.plugin.core.log.Log
message: "Completed Dagster job run audit with status: {{
outputs.classify_run_outcome.value }}"
- id: log_audit_complete
type: io.kestra.plugin.core.log.Log
description: "Post-audit status line recorded on every run regardless of branch,
for a continuous job-reliability trend in the execution history."
message: "Dagster job compliance audit: job_name={{ inputs.job_name }},
status={{ outputs.classify_run_outcome.value }}, auto_remediate={{
inputs.auto_remediate }}, dry_run={{ inputs.dry_run }}, execution={{
execution.id }}."
errors:
- id: alert_flow_failure
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: "Alert Slack when the sentinel flow itself fails, so a broken audit
never silently stops monitoring the job."
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{
"text": "Dagster job run compliance gate flow {{ flow.id }} FAILED (execution {{ execution.id }}). Job compliance status is now unknown; check the task logs and the Dagster UI manually."
}