पाठ 13 / 25

Trigger Rules

Upstream tasks की स्थितियों के अनुसार नियंत्रित करें कि task कब चलेगा।

सिर्फ़ "सब सफल" नहीं

डिफ़ॉल्ट रूप से task तब चलता है जब सभी upstream tasks सफल हों (all_success)। अन्य नियमों में all_done (सब ख़त्म होने पर, नतीजा चाहे जो हो, चलाओ: cleanup और notifications के लिए अच्छा), one_failed (कुछ विफल होने पर alert चलाओ), none_failed और none_failed_min_one_success (skips के बाद जारी रखो, कोई upstream विफल हो तो विफल) शामिल हैं। सही नियम चुनना ही वह तरीक़ा है जिससे ऐसे cleanup steps बनते हैं जो हमेशा चलें और ऐसे alerts जो सिर्फ़ विफलता पर चलें।

नियमों का मूल्यांकन, चलाकर

मैंने upstream स्थितियों success और failed के लिए चार नियमों का सादा-Python मॉडल चलाया। सिर्फ़ all_done और one_failed task को चलने देंगे; all_success और none_failed नहीं।

def ok(rule, states):
    s = list(states)
    return {"all_success": all(x == "success" for x in s),
            "all_done": all(x in ("success", "failed", "skipped") for x in s),
            "one_failed": any(x == "failed" for x in s),
            "none_failed": all(x != "failed" for x in s)}[rule]

ups = ["success", "failed"]
print({r: ok(r, ups) for r in ("all_success", "all_done", "one_failed", "none_failed")})

Output:

{'all_success': False, 'all_done': True, 'one_failed': True, 'none_failed': False}

Cleanup के लिए all_done

अस्थायी tables और files को trigger_rule="all_done" वाले task में हटाएँ ताकि cleanup विफलताओं के बाद भी चले।

त्वरित जाँच: कौन-सा नियम failure alert तभी चलाता है जब upstream task विफल हो?

  • all_success
  • one_failed
  • always_skip
  • none_failed
Answer

one_failed — one_failed तब चलता है जब कम से कम एक upstream task विफल हो चुका हो।