id: drone-mission-go-no-go-gate
namespace: company.team
inputs:
- id: mission_id
type: STRING
displayName: Mission id
defaults: INS-1042
- id: site
type: STRING
displayName: Site
defaults: Esbjerg turbine T17
- id: latitude
type: FLOAT
displayName: Latitude
defaults: 55.47
- id: longitude
type: FLOAT
displayName: Longitude
defaults: 8.45
- id: start
type: DATETIME
displayName: Planned take-off
description: ISO-8601 timestamp such as 2026-10-18T09:00:00Z. Leave empty to
check the next full hour.
required: false
- id: duration_minutes
type: INT
displayName: Flight duration (minutes)
defaults: 45
- id: max_wind_ms
type: FLOAT
displayName: Max sustained wind at 120 m (m/s)
description: Enterprise quadcopters are typically rated for about 12 m/s; 10
leaves a margin for the return leg.
defaults: 10.0
- id: max_gust_ms
type: FLOAT
displayName: Max gust at 10 m (m/s)
defaults: 12.0
- id: max_precip_probability
type: INT
displayName: Max precipitation probability (%)
defaults: 30
- id: min_visibility_m
type: INT
displayName: Min visibility (m)
description: 4800 m is the FAA Part 107 minimum of 3 statute miles.
defaults: 4800
- id: max_kp
type: FLOAT
displayName: Max planetary Kp index
description: NOAA's G1 geomagnetic storm level starts at Kp 5. Storms degrade
GNSS positioning and RTK fixes, so 4 keeps a margin.
defaults: 4.0
- id: daylight_only
type: BOOL
displayName: Daylight flights only
defaults: true
- id: notify_slack
type: BOOL
displayName: Post the verdict to Slack
description: Send the verdict to the Slack incoming webhook stored in the
SLACK_WEBHOOK_URL secret. Set to false for a dry run that only logs.
defaults: true
- id: fail_on_no_go
type: BOOL
displayName: Fail the execution on NO-GO
description: Turn the check into a hard gate, so a parent flow or the webhook
caller gets a failed execution when the flight is not cleared.
defaults: false
triggers:
- id: on_mission_booked
type: io.kestra.plugin.core.trigger.Webhook
description: Event-driven entry point. The mission planner POSTs the mission as
JSON whenever a flight is booked or moved; any input id can be sent as a
body field. The call waits for the verdict and returns the flow outputs as
the HTTP response. The key guards the URL, so keep it in a secret.
key: "{{ secret('DRONE_GATE_WEBHOOK_KEY') }}"
wait: true
returnOutputs: true
tasks:
- id: mission
type: io.kestra.plugin.core.output.OutputValues
description: Resolve each mission field once. A webhook body field wins over the
input of the same name, and the take-off time is normalised to UTC,
defaulting to the next full hour.
values:
mission_id: "{{ trigger.body.mission_id ?? inputs.mission_id }}"
site: "{{ trigger.body.site ?? inputs.site }}"
latitude: "{{ trigger.body.latitude ?? inputs.latitude }}"
longitude: "{{ trigger.body.longitude ?? inputs.longitude }}"
start_utc: "{{ (trigger.body.start ?? inputs.start ?? now() | dateAdd(1,
'HOURS') | date(\"yyyy-MM-dd'T'HH:00:00'Z'\", timeZone=\"UTC\")) |
date(\"yyyy-MM-dd'T'HH:mm:ss\", timeZone=\"UTC\") }}"
duration_minutes: "{{ trigger.body.duration_minutes ?? inputs.duration_minutes }}"
max_wind_ms: "{{ trigger.body.max_wind_ms ?? inputs.max_wind_ms }}"
max_gust_ms: "{{ trigger.body.max_gust_ms ?? inputs.max_gust_ms }}"
max_precip_probability: "{{ trigger.body.max_precip_probability ??
inputs.max_precip_probability }}"
min_visibility_m: "{{ trigger.body.min_visibility_m ?? inputs.min_visibility_m }}"
max_kp: "{{ trigger.body.max_kp ?? inputs.max_kp }}"
daylight_only: "{{ trigger.body.daylight_only ?? inputs.daylight_only }}"
- id: forecasts
type: io.kestra.plugin.core.flow.Parallel
description: The space-weather and site-weather forecasts are independent, so
they download side by side. Both files stay attached to the execution as
the evidence behind the verdict.
tasks:
- id: kp_forecast
type: io.kestra.plugin.core.http.Download
description: NOAA SWPC planetary Kp index in 3-hour blocks, observed, estimated
and predicted about 2.5 days ahead. Public, no API key.
uri: https://services.swpc.noaa.gov/products/noaa-planetary-k-index-forecast.json
retry:
type: constant
interval: PT10S
maxAttempts: 3
- id: site_weather
type: io.kestra.plugin.core.http.Download
description: Open-Meteo hourly forecast for the site, in UTC and m/s. Wind at
120 m matches the usual maximum flight altitude. Public, no API key.
uri: https://api.open-meteo.com/v1/forecast
params:
latitude: "{{ outputs.mission.values.latitude }}"
longitude: "{{ outputs.mission.values.longitude }}"
hourly: wind_speed_120m,wind_gusts_10m,precipitation_probability,visibility,is_day
wind_speed_unit: ms
timezone: UTC
forecast_days: "3"
retry:
type: constant
interval: PT10S
maxAttempts: 3
- id: evaluate
type: io.kestra.plugin.jdbc.duckdb.Query
description: >
DuckDB unnests Open-Meteo's hourly arrays, joins every hour to its 3-hour
Kp block and lists the limits each hour breaks. The flight is GO only when
every hour it touches passes, and missing data counts as a failure. A
gaps-and-islands query finds the first run of safe hours long enough for
the flight. Mission values arrive as a JSON file, so webhook input is read
as data and never spliced into the SQL.
inputFiles:
kp.json: "{{ outputs.kp_forecast.uri }}"
weather.json: "{{ outputs.site_weather.uri }}"
mission.json: "{{ outputs.mission.values | toJson }}"
fetchType: FETCH_ONE
sql: |
WITH params AS (
SELECT CAST(start_utc AS TIMESTAMP) AS mission_start,
CAST(start_utc AS TIMESTAMP) + to_minutes(CAST(duration_minutes AS BIGINT)) AS mission_end,
CAST(duration_minutes AS INTEGER) AS duration_minutes,
CAST(max_wind_ms AS DOUBLE) AS max_wind_ms,
CAST(max_gust_ms AS DOUBLE) AS max_gust_ms,
CAST(max_precip_probability AS DOUBLE) AS max_precip_probability,
CAST(min_visibility_m AS DOUBLE) AS min_visibility_m,
CAST(max_kp AS DOUBLE) AS max_kp,
CAST(daylight_only AS BOOLEAN) AS daylight_only
FROM read_json('{{ workingDir }}/mission.json', columns = {
start_utc: 'VARCHAR', duration_minutes: 'VARCHAR', max_wind_ms: 'VARCHAR', max_gust_ms: 'VARCHAR',
max_precip_probability: 'VARCHAR', min_visibility_m: 'VARCHAR', max_kp: 'VARCHAR', daylight_only: 'VARCHAR'})
),
kp AS (
SELECT CAST(time_tag AS TIMESTAMP) AS block_start, max(kp) AS kp
FROM read_json('{{ workingDir }}/kp.json', format = 'array',
columns = {time_tag: 'VARCHAR', kp: 'DOUBLE', observed: 'VARCHAR', noaa_scale: 'VARCHAR'})
GROUP BY 1
),
weather AS (
SELECT CAST(ts AS TIMESTAMP) AS hour, wind_120m, gust_10m, precip_probability, visibility_m, is_day
FROM (
SELECT unnest(hourly."time") AS ts,
unnest(hourly.wind_speed_120m) AS wind_120m,
unnest(hourly.wind_gusts_10m) AS gust_10m,
unnest(hourly.precipitation_probability) AS precip_probability,
unnest(hourly.visibility) AS visibility_m,
unnest(hourly.is_day) AS is_day
FROM read_json('{{ workingDir }}/weather.json', columns = {
hourly: 'STRUCT("time" VARCHAR[], wind_speed_120m DOUBLE[], wind_gusts_10m DOUBLE[], precipitation_probability DOUBLE[], visibility DOUBLE[], is_day INTEGER[])'})
)
),
checked AS (
SELECT w.*, k.kp,
concat_ws(', ',
CASE WHEN k.kp IS NULL THEN 'no Kp forecast'
WHEN k.kp > p.max_kp THEN printf('geomagnetic Kp %.1f', k.kp) END,
CASE WHEN w.wind_120m IS NULL THEN 'no wind forecast'
WHEN w.wind_120m > p.max_wind_ms THEN printf('wind %.1f m/s at 120 m', w.wind_120m) END,
CASE WHEN w.gust_10m IS NULL THEN 'no gust forecast'
WHEN w.gust_10m > p.max_gust_ms THEN printf('gusts %.1f m/s', w.gust_10m) END,
CASE WHEN w.precip_probability IS NULL THEN 'no rain forecast'
WHEN w.precip_probability > p.max_precip_probability THEN printf('rain %.0f%%', w.precip_probability) END,
CASE WHEN w.visibility_m IS NULL THEN 'no visibility forecast'
WHEN w.visibility_m < p.min_visibility_m THEN printf('visibility %.1f km', w.visibility_m / 1000) END,
CASE WHEN p.daylight_only AND coalesce(w.is_day, 0) = 0 THEN 'night' END) AS reasons
FROM weather w
CROSS JOIN params p
LEFT JOIN kp k ON w.hour >= k.block_start AND w.hour < k.block_start + INTERVAL 3 HOUR
),
flight AS (
SELECT c.* FROM checked c CROSS JOIN params p
WHERE c.hour < p.mission_end AND c.hour + INTERVAL 1 HOUR > p.mission_start
),
summary AS (
SELECT coalesce(min(f.hour) <= p.mission_start AND max(f.hour) + INTERVAL 1 HOUR >= p.mission_end, false) AS covered,
count(f.hour) FILTER (WHERE f.reasons <> '') AS failing_hours,
string_agg(strftime(f.hour, '%H:%M') || ' ' || f.reasons, '; ' ORDER BY f.hour) FILTER (WHERE f.reasons <> '') AS failures,
max(f.kp) AS kp, max(f.wind_120m) AS wind, max(f.gust_10m) AS gust,
max(f.precip_probability) AS rain, min(f.visibility_m) AS visibility
FROM params p
LEFT JOIN flight f ON true
GROUP BY p.mission_start, p.mission_end
),
islands AS (
SELECT c.hour, date_diff('hour', TIMESTAMP '1970-01-01', c.hour) - row_number() OVER (ORDER BY c.hour) AS island
FROM checked c CROSS JOIN params p
WHERE c.reasons = '' AND c.hour >= date_trunc('hour', p.mission_start)
),
safe_window AS (
SELECT min(hour) AS window_start, max(hour) + INTERVAL 1 HOUR AS window_end
FROM islands
GROUP BY island
HAVING count(*) * 60 >= (SELECT duration_minutes FROM params)
ORDER BY window_start
LIMIT 1
),
strip AS (
SELECT string_agg(CASE WHEN reasons = '' THEN ':large_green_circle:' ELSE ':red_circle:' END
|| CASE WHEN n % 6 = 0 THEN ' ' ELSE '' END, '' ORDER BY hour) AS strip
FROM (SELECT c.hour, c.reasons, row_number() OVER (ORDER BY c.hour) AS n
FROM checked c CROSS JOIN params p
WHERE c.hour >= date_trunc('hour', p.mission_start)
AND c.hour < date_trunc('hour', p.mission_start) + INTERVAL 24 HOUR)
)
SELECT CASE WHEN p.duration_minutes > 0 AND s.covered AND s.failing_hours = 0 THEN 'GO' ELSE 'NO_GO' END AS verdict,
CASE WHEN p.duration_minutes <= 0 THEN 'duration_minutes must be positive'
WHEN NOT s.covered THEN 'the flight is outside the forecast horizon'
ELSE coalesce(s.failures, 'none') END AS reasons,
strftime(p.mission_start, '%Y-%m-%d %H:%M') AS mission_start,
strftime(p.mission_end, '%Y-%m-%d %H:%M') AS mission_end,
coalesce(nullif(concat_ws(', ',
printf('wind %.1f m/s at 120 m', s.wind), printf('gusts %.1f m/s', s.gust),
printf('rain %.0f%%', s.rain), printf('visibility %.1f km', s.visibility / 1000),
printf('Kp %.1f', s.kp)), ''), 'no forecast data') AS conditions,
coalesce(strftime(w.window_start, '%Y-%m-%d %H:%M'), 'none') AS window_start,
coalesce(strftime(w.window_end, '%Y-%m-%d %H:%M'), 'none') AS window_end,
coalesce(st.strip, '') AS strip_24h,
strftime(date_trunc('hour', p.mission_start), '%H:%M') AS strip_from
FROM params p
CROSS JOIN summary s
CROSS JOIN strip st
LEFT JOIN safe_window w ON true
- id: label_verdict
type: io.kestra.plugin.core.execution.Labels
description: Tag the execution so GO and NO-GO runs can be filtered in the
Executions list.
labels:
mission: "{{ outputs.mission.values.mission_id }}"
verdict: "{{ outputs.evaluate.row.verdict }}"
- id: log_verdict
type: io.kestra.plugin.core.log.Log
message: >-
{{ outputs.evaluate.row.verdict }} for mission {{
outputs.mission.values.mission_id }} at {{ outputs.mission.values.site }},
{{ outputs.evaluate.row.mission_start }} to {{
outputs.evaluate.row.mission_end }} UTC. Worst case: {{
outputs.evaluate.row.conditions }}. Failing hours: {{
outputs.evaluate.row.reasons }}. Safe window: {{
outputs.evaluate.row.window_start }} to {{ outputs.evaluate.row.window_end
}} UTC.
- id: notify
type: io.kestra.plugin.core.flow.If
description: Post the verdict to Slack only when notify_slack is true, so a dry
run just logs.
condition: "{{ inputs.notify_slack }}"
then:
- id: slack_verdict
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
messageText: |
{% set r = outputs.evaluate.row %}{% set m = outputs.mission.values %}{% if r.verdict == 'GO' %}:large_green_circle: *GO*{% else %}:red_circle: *NO-GO*{% endif %} for drone mission `{{ m.mission_id }}` at *{{ m.site }}*
Flight: {{ r.mission_start }} to {{ r.mission_end }} UTC
Worst case: {{ r.conditions }}
{% if r.verdict != 'GO' %}Why: {{ r.reasons }}
{% endif %}{% if r.window_start == 'none' %}No safe window left in the forecast horizon.{% elseif r.verdict == 'GO' %}Safe until {{ r.window_end }} UTC{% else %}Next safe window: {{ r.window_start }} to {{ r.window_end }} UTC{% endif %}
{% if r.strip_24h != '' %}Next 24 h from {{ r.strip_from }} UTC: {{ r.strip_24h }}
{% endif %}Kestra execution: {{ execution.id }}
- id: gate
type: io.kestra.plugin.core.execution.Fail
description: Optional hard gate. With fail_on_no_go set, a NO-GO fails the
execution, so a parent flow calling this one as a Subflow stops before the
flight plan is uploaded.
condition: "{{ inputs.fail_on_no_go and outputs.evaluate.row.verdict != 'GO' }}"
errorMessage: "NO-GO for drone mission {{ outputs.mission.values.mission_id }}:
{{ outputs.evaluate.row.reasons }}"
errors:
- id: check_failed
type: io.kestra.plugin.core.flow.If
description: Fail safe. When a forecast cannot be fetched or evaluated, Slack
hears NO-GO instead of nothing.
condition: "{{ inputs.notify_slack and outputs.evaluate is not defined }}"
then:
- id: slack_check_failed
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
messageText: ":red_circle: *NO-GO (check failed)* for drone mission `{{
outputs.mission.values.mission_id ?? inputs.mission_id }}`: a forecast
could not be fetched or evaluated, so the flight is not cleared.
Kestra execution: {{ execution.id }}"
outputs:
- id: verdict
type: STRING
value: "{{ outputs.evaluate.row.verdict }}"
- id: reasons
type: STRING
value: "{{ outputs.evaluate.row.reasons }}"
- id: conditions
type: STRING
value: "{{ outputs.evaluate.row.conditions }}"
- id: safe_window_start
type: STRING
value: "{{ outputs.evaluate.row.window_start }}"
- id: safe_window_end
type: STRING
value: "{{ outputs.evaluate.row.window_end }}"