You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by zh...@apache.org on 2022/12/18 10:17:50 UTC

[dolphinscheduler-sdk-python] branch main updated: support cache task (#50)

This is an automated email from the ASF dual-hosted git repository.

zhoujieguang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler-sdk-python.git


The following commit(s) were added to refs/heads/main by this push:
     new cf62349  support cache task (#50)
cf62349 is described below

commit cf623496449219a3134f82de62c452bc30fe1d22
Author: JieguangZhou <ji...@163.com>
AuthorDate: Sun Dec 18 18:17:43 2022 +0800

    support cache task (#50)
---
 examples/yaml_define/MoreConfiguration.yaml |  1 +
 src/pydolphinscheduler/constants.py         |  7 +++++++
 src/pydolphinscheduler/core/task.py         | 12 ++++++++++++
 tests/core/test_engine.py                   |  1 +
 tests/core/test_task.py                     |  1 +
 5 files changed, 22 insertions(+)

diff --git a/examples/yaml_define/MoreConfiguration.yaml b/examples/yaml_define/MoreConfiguration.yaml
index 5f4d9d3..678315a 100644
--- a/examples/yaml_define/MoreConfiguration.yaml
+++ b/examples/yaml_define/MoreConfiguration.yaml
@@ -35,5 +35,6 @@ tasks:
     fail_retry_times: 30
     fail_retry_interval: 5
     timeout: 60
+    is_cahce: true
     local_params:
       - { "prop": "n", "direct": "IN", "type": "VARCHAR", "value": "${n}" }
diff --git a/src/pydolphinscheduler/constants.py b/src/pydolphinscheduler/constants.py
index 0519688..e158892 100644
--- a/src/pydolphinscheduler/constants.py
+++ b/src/pydolphinscheduler/constants.py
@@ -35,6 +35,13 @@ class TaskFlag(str):
     NO = "NO"
 
 
+class IsCache(str):
+    """Constants for Cache."""
+
+    YES = "YES"
+    NO = "NO"
+
+
 class TaskTimeoutFlag(str):
     """Constants for task timeout flag."""
 
diff --git a/src/pydolphinscheduler/core/task.py b/src/pydolphinscheduler/core/task.py
index 32d87bc..7b942eb 100644
--- a/src/pydolphinscheduler/core/task.py
+++ b/src/pydolphinscheduler/core/task.py
@@ -26,6 +26,7 @@ from typing import Dict, List, Optional, Sequence, Set, Tuple, Union
 from pydolphinscheduler import configuration
 from pydolphinscheduler.constants import (
     Delimiter,
+    IsCache,
     ResourceKey,
     Symbol,
     TaskFlag,
@@ -100,6 +101,7 @@ class Task(Base):
         "timeout_flag",
         "timeout_notify_strategy",
         "timeout",
+        "is_cache",
     }
 
     # task default attribute will into `task_params` property
@@ -141,6 +143,7 @@ class Task(Base):
         wait_start_timeout: Optional[Dict] = None,
         condition_result: Optional[Dict] = None,
         resource_plugin: Optional[ResourcePlugin] = None,
+        is_cache: Optional[bool] = False,
         *args,
         **kwargs,
     ):
@@ -148,6 +151,7 @@ class Task(Base):
         super().__init__(name, description)
         self.task_type = task_type
         self.flag = flag
+        self._is_cache = is_cache
         self.task_priority = task_priority
         self.worker_group = worker_group
         self._environment_name = environment_name
@@ -214,6 +218,14 @@ class Task(Base):
         """Whether the timeout attribute is being set or not."""
         return TaskTimeoutFlag.ON if self._timeout else TaskTimeoutFlag.OFF
 
+    @property
+    def is_cache(self) -> str:
+        """Whether the cache is being set or not."""
+        if isinstance(self._is_cache, bool):
+            return IsCache.YES if self._is_cache else IsCache.NO
+        else:
+            raise PyDSParamException("is_cache must be a bool")
+
     @property
     def resource_list(self) -> List[Dict[str, Resource]]:
         """Get task define attribute `resource_list`."""
diff --git a/tests/core/test_engine.py b/tests/core/test_engine.py
index ba44fad..90a14d0 100644
--- a/tests/core/test_engine.py
+++ b/tests/core/test_engine.py
@@ -122,6 +122,7 @@ def test_property_task_params(mock_resource, mock_code_version, attr, expect):
                     "waitStartTimeout": {},
                 },
                 "flag": "YES",
+                "isCache": "NO",
                 "taskPriority": "MEDIUM",
                 "workerGroup": "default",
                 "environmentCode": None,
diff --git a/tests/core/test_task.py b/tests/core/test_task.py
index 40a3e9c..250573a 100644
--- a/tests/core/test_task.py
+++ b/tests/core/test_task.py
@@ -251,6 +251,7 @@ def test_task_get_define():
             "waitStartTimeout": {},
         },
         "flag": "YES",
+        "isCache": "NO",
         "taskPriority": "MEDIUM",
         "workerGroup": "default",
         "environmentCode": None,