trigger_rule.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #
  2. # Licensed to the Apache Software Foundation (ASF) under one
  3. # or more contributor license agreements. See the NOTICE file
  4. # distributed with this work for additional information
  5. # regarding copyright ownership. The ASF licenses this file
  6. # to you under the Apache License, Version 2.0 (the
  7. # "License"); you may not use this file except in compliance
  8. # with the License. You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing,
  13. # software distributed under the License is distributed on an
  14. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. # KIND, either express or implied. See the License for the
  16. # specific language governing permissions and limitations
  17. # under the License.
  18. from __future__ import annotations
  19. from enum import Enum
  20. class TriggerRule(str, Enum):
  21. """Class with task's trigger rules."""
  22. ALL_SUCCESS = "all_success"
  23. ALL_FAILED = "all_failed"
  24. ALL_DONE = "all_done"
  25. ALL_DONE_SETUP_SUCCESS = "all_done_setup_success"
  26. ONE_SUCCESS = "one_success"
  27. ONE_FAILED = "one_failed"
  28. ONE_DONE = "one_done"
  29. NONE_FAILED = "none_failed"
  30. NONE_FAILED_OR_SKIPPED = "none_failed_or_skipped"
  31. NONE_SKIPPED = "none_skipped"
  32. DUMMY = "dummy"
  33. ALWAYS = "always"
  34. NONE_FAILED_MIN_ONE_SUCCESS = "none_failed_min_one_success"
  35. ALL_SKIPPED = "all_skipped"
  36. @classmethod
  37. def is_valid(cls, trigger_rule: str) -> bool:
  38. """Validate a trigger rule."""
  39. return trigger_rule in cls.all_triggers()
  40. @classmethod
  41. def all_triggers(cls) -> set[str]:
  42. """Return all trigger rules."""
  43. return set(cls.__members__.values())
  44. def __str__(self) -> str:
  45. return self.value