task_dependent_example.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # Licensed to the Apache Software Foundation (ASF) under one
  2. # or more contributor license agreements. See the NOTICE file
  3. # distributed with this work for additional information
  4. # regarding copyright ownership. The ASF licenses this file
  5. # to you under the Apache License, Version 2.0 (the
  6. # "License"); you may not use this file except in compliance
  7. # with the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing,
  12. # software distributed under the License is distributed on an
  13. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. # KIND, either express or implied. See the License for the
  15. # specific language governing permissions and limitations
  16. # under the License.
  17. r"""
  18. A example workflow for task dependent.
  19. This example will create two workflows named `task_dependent` and `task_dependent_external`.
  20. `task_dependent` is true workflow define and run task dependent, while `task_dependent_external`
  21. define outside workflow and task from dependent.
  22. After this script submit, we would get workflow as below:
  23. task_dependent_external:
  24. task_1
  25. task_2
  26. task_3
  27. task_dependent:
  28. task_dependent(this task dependent on task_dependent_external.task_1 and task_dependent_external.task_2).
  29. """
  30. from pydolphinscheduler.constants import ProcessDefinitionDefault
  31. from pydolphinscheduler.core.process_definition import ProcessDefinition
  32. from pydolphinscheduler.tasks.dependent import And, Dependent, DependentItem, Or
  33. from pydolphinscheduler.tasks.shell import Shell
  34. with ProcessDefinition(
  35. name="task_dependent_external",
  36. tenant="tenant_exists",
  37. ) as pd:
  38. task_1 = Shell(name="task_1", command="echo task 1")
  39. task_2 = Shell(name="task_2", command="echo task 2")
  40. task_3 = Shell(name="task_3", command="echo task 3")
  41. pd.submit()
  42. with ProcessDefinition(
  43. name="task_dependent_example",
  44. tenant="tenant_exists",
  45. ) as pd:
  46. task = Dependent(
  47. name="task_dependent",
  48. dependence=And(
  49. Or(
  50. DependentItem(
  51. project_name=ProcessDefinitionDefault.PROJECT,
  52. process_definition_name="task_dependent_external",
  53. dependent_task_name="task_1",
  54. ),
  55. DependentItem(
  56. project_name=ProcessDefinitionDefault.PROJECT,
  57. process_definition_name="task_dependent_external",
  58. dependent_task_name="task_2",
  59. ),
  60. )
  61. ),
  62. )
  63. pd.submit()