|
10 | 10 | import warnings |
11 | 11 | from copy import deepcopy |
12 | 12 | from datetime import datetime, timedelta |
13 | | -from functools import partial, reduce |
| 13 | +from functools import partial |
14 | 14 | from typing import Any, Callable, Dict, List, Tuple, Union |
15 | 15 |
|
16 | 16 | from airflow import configuration |
@@ -756,66 +756,6 @@ def process_file_with_datasets(file: str, datasets_conditions: str) -> Any: |
756 | 756 | datasets_uri = utils.get_datasets_uri_yaml_file(file, list(dataset_map.keys())) |
757 | 757 | return [Dataset(uri) for uri in datasets_uri] |
758 | 758 |
|
759 | | - @staticmethod |
760 | | - def _init_watchers(watchers_data): |
761 | | - """Initialize watcher objects from configuration.""" |
762 | | - from dagfactory.utils import _import_from_string |
763 | | - |
764 | | - watchers = [] |
765 | | - for watcher in watchers_data: |
766 | | - watcher_class = _import_from_string(watcher["callable"]) |
767 | | - trigger_data = watcher.get("trigger", {}) |
768 | | - trigger_class = _import_from_string(trigger_data.get("callable")) |
769 | | - trigger_params = trigger_data.get("params", {}) |
770 | | - watchers.append(watcher_class(name=watcher.get("name"), trigger=trigger_class(**trigger_params))) |
771 | | - return watchers |
772 | | - |
773 | | - @staticmethod |
774 | | - def _combine_assets(assets, op: str): |
775 | | - """Combine a list of Asset objects using logical operators.""" |
776 | | - if op == "or": |
777 | | - return reduce(lambda a, b: a | b, assets) |
778 | | - elif op == "and": |
779 | | - return reduce(lambda a, b: a & b, assets) |
780 | | - else: |
781 | | - raise ValueError(f"Unknown operator: {op}") |
782 | | - |
783 | | - @staticmethod |
784 | | - def _is_asset(d): |
785 | | - from airflow.sdk import Asset |
786 | | - |
787 | | - if not isinstance(d, dict): |
788 | | - return False |
789 | | - for key, value in d.items(): |
790 | | - if isinstance(value, Asset): |
791 | | - return True |
792 | | - elif isinstance(value, list): |
793 | | - if any(isinstance(item, Asset) for item in value): |
794 | | - return True |
795 | | - elif isinstance(value, dict): |
796 | | - if DagBuilder._is_asset(value): |
797 | | - return True |
798 | | - return False |
799 | | - |
800 | | - @staticmethod |
801 | | - def _asset_schedule(value): |
802 | | - """Recursively parse and construct assets or combinations of assets.""" |
803 | | - from airflow.sdk import Asset |
804 | | - |
805 | | - if isinstance(value, dict): |
806 | | - if "or" in value: |
807 | | - assets = [DagBuilder._asset_schedule(item) for item in value["or"]] |
808 | | - return DagBuilder._combine_assets(assets, "or") |
809 | | - elif "and" in value: |
810 | | - assets = [DagBuilder._asset_schedule(item) for item in value["and"]] |
811 | | - return DagBuilder._combine_assets(assets, "and") |
812 | | - elif isinstance(value, list): |
813 | | - return [asset for asset in value] |
814 | | - elif isinstance(value, Asset): |
815 | | - return value |
816 | | - else: |
817 | | - raise TypeError(f"Unexpected data type: {type(value)}") |
818 | | - |
819 | 759 | @staticmethod |
820 | 760 | def configure_schedule(dag_params: Dict[str, Any], dag_kwargs: Dict[str, Any]) -> None: |
821 | 761 | """ |
@@ -862,17 +802,14 @@ def configure_schedule(dag_params: Dict[str, Any], dag_kwargs: Dict[str, Any]) - |
862 | 802 | schedule.pop("datasets") |
863 | 803 | else: |
864 | 804 | schedule = dag_params.get("schedule") |
865 | | - if DagBuilder._is_asset(schedule): |
866 | | - dag_kwargs["schedule"] = DagBuilder._asset_schedule(schedule) |
| 805 | + if ( |
| 806 | + utils.check_dict_key(dag_params, "schedule") |
| 807 | + and isinstance(dag_params["schedule"], str) |
| 808 | + and dag_params["schedule"].strip().lower() == "none" |
| 809 | + ): |
| 810 | + dag_kwargs["schedule"] = None |
867 | 811 | else: |
868 | | - if ( |
869 | | - utils.check_dict_key(dag_params, "schedule") |
870 | | - and isinstance(dag_params["schedule"], str) |
871 | | - and dag_params["schedule"].strip().lower() == "none" |
872 | | - ): |
873 | | - dag_kwargs["schedule"] = None |
874 | | - else: |
875 | | - dag_kwargs["schedule"] = schedule |
| 812 | + dag_kwargs["schedule"] = schedule |
876 | 813 |
|
877 | 814 | @staticmethod |
878 | 815 | def _normalise_tasks_config(tasks_cfg: Any) -> Dict[str, Dict[str, Any]]: |
|
0 commit comments