You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by GitBox <gi...@apache.org> on 2022/09/16 02:53:57 UTC

[GitHub] [dolphinscheduler] zhongjiajie commented on a diff in pull request #11941: [Feature][PyDolphinScheduler] Support DVC task in pyds #11922

zhongjiajie commented on code in PR #11941:
URL: https://github.com/apache/dolphinscheduler/pull/11941#discussion_r972569722


##########
dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/tasks/dvc.py:
##########
@@ -0,0 +1,109 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""Task dvc."""
+
+from pydolphinscheduler.constants import TaskType
+from pydolphinscheduler.core.task import Task
+
+
+class DvcTaskType(str):
+    """Constants for dvc task type."""
+
+    INIT = "Init DVC"
+    DOWNLOAD = "Download"
+    UPLOAD = "Upload"
+
+
+class DVCInit(Task):
+    """Task DVC Init object, declare behavior for DVC Init task to dolphinscheduler."""
+
+    dvc_task_type = DvcTaskType.INIT
+
+    _task_custom_attr = {
+        "dvc_task_type",
+        "dvc_repository",
+        "dvc_store_url",
+    }
+
+    def __init__(self, name: str, repository: str, store_url: str, *args, **kwargs):
+        super().__init__(name, TaskType.DVC, *args, **kwargs)
+        self.dvc_repository = repository
+        self.dvc_store_url = store_url

Review Comment:
   Maybe we can add a new class `BaseDVC(Task)` to handle the same logic of attribute `dvc_task_type` and `dvc_repository`, and then remove the class `DvcTaskType`(because it only usage one time, but I do not have strong opinion here). I write some demo about it
   
   ```py
   class BaseDVC(Task):
   
        dvc_task_type = None
   
        _task_custom_attr = {
            "dvc_task_type",
            "dvc_repository",
        }
   
        # Or other name you like
        _child_task_dvc_attr = set()
   
        def __init__(self, name: str, repository: str, *args, **kwargs):
            super().__init__(name, TaskType.DVC, *args, **kwargs)
            self.dvc_repository = repository
            self.dvc_store_url = store_url
   
       @property
       def task_params(self) -> Dict:
           if not self.dvc_task_type:
               raise PyDSParamException("balabala")
           self._task_custom_attr.update(self. _child_task_dvc_attr)
           return super().task_params
   
   class DVCInit(BaseDVC):
        """Task DVC Init object, declare behavior for DVC Init task to dolphinscheduler."""
   
        dvc_task_type = "Init DVC"
   
       _child_task_dvc_attr = {
           "dvc_store_url",
       }
   
        def __init__(self, name: str, repository: str, store_url: str, *args, **kwargs):
            super().__init__(name, repository, *args, **kwargs)
            self.dvc_store_url = store_url
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org