|
9 | 9 | import re |
10 | 10 | import warnings |
11 | 11 | from copy import deepcopy |
| 12 | + |
12 | 13 | from datetime import datetime |
13 | | -from functools import partial, reduce |
| 14 | +from functools import partial |
14 | 15 | from typing import Any, Callable, Dict, List, Tuple, Union |
15 | 16 |
|
16 | 17 | from airflow import configuration |
@@ -594,66 +595,6 @@ def process_file_with_datasets(file: str, datasets_conditions: str) -> Any: |
594 | 595 | datasets_uri = utils.get_datasets_uri_yaml_file(file, list(dataset_map.keys())) |
595 | 596 | return [Dataset(uri) for uri in datasets_uri] |
596 | 597 |
|
597 | | - @staticmethod |
598 | | - def _init_watchers(watchers_data): |
599 | | - """Initialize watcher objects from configuration.""" |
600 | | - from dagfactory.utils import _import_from_string |
601 | | - |
602 | | - watchers = [] |
603 | | - for watcher in watchers_data: |
604 | | - watcher_class = _import_from_string(watcher["callable"]) |
605 | | - trigger_data = watcher.get("trigger", {}) |
606 | | - trigger_class = _import_from_string(trigger_data.get("callable")) |
607 | | - trigger_params = trigger_data.get("params", {}) |
608 | | - watchers.append(watcher_class(name=watcher.get("name"), trigger=trigger_class(**trigger_params))) |
609 | | - return watchers |
610 | | - |
611 | | - @staticmethod |
612 | | - def _combine_assets(assets, op: str): |
613 | | - """Combine a list of Asset objects using logical operators.""" |
614 | | - if op == "or": |
615 | | - return reduce(lambda a, b: a | b, assets) |
616 | | - elif op == "and": |
617 | | - return reduce(lambda a, b: a & b, assets) |
618 | | - else: |
619 | | - raise ValueError(f"Unknown operator: {op}") |
620 | | - |
621 | | - @staticmethod |
622 | | - def _is_asset(d): |
623 | | - from airflow.sdk import Asset |
624 | | - |
625 | | - if not isinstance(d, dict): |
626 | | - return False |
627 | | - for key, value in d.items(): |
628 | | - if isinstance(value, Asset): |
629 | | - return True |
630 | | - elif isinstance(value, list): |
631 | | - if any(isinstance(item, Asset) for item in value): |
632 | | - return True |
633 | | - elif isinstance(value, dict): |
634 | | - if DagBuilder._is_asset(value): |
635 | | - return True |
636 | | - return False |
637 | | - |
638 | | - @staticmethod |
639 | | - def _asset_schedule(value): |
640 | | - """Recursively parse and construct assets or combinations of assets.""" |
641 | | - from airflow.sdk import Asset |
642 | | - |
643 | | - if isinstance(value, dict): |
644 | | - if "or" in value: |
645 | | - assets = [DagBuilder._asset_schedule(item) for item in value["or"]] |
646 | | - return DagBuilder._combine_assets(assets, "or") |
647 | | - elif "and" in value: |
648 | | - assets = [DagBuilder._asset_schedule(item) for item in value["and"]] |
649 | | - return DagBuilder._combine_assets(assets, "and") |
650 | | - elif isinstance(value, list): |
651 | | - return [asset for asset in value] |
652 | | - elif isinstance(value, Asset): |
653 | | - return value |
654 | | - else: |
655 | | - raise TypeError(f"Unexpected data type: {type(value)}") |
656 | | - |
657 | 598 | @staticmethod |
658 | 599 | def configure_schedule(dag_params: Dict[str, Any], dag_kwargs: Dict[str, Any]) -> None: |
659 | 600 | """ |
@@ -700,17 +641,14 @@ def configure_schedule(dag_params: Dict[str, Any], dag_kwargs: Dict[str, Any]) - |
700 | 641 | schedule.pop("datasets") |
701 | 642 | else: |
702 | 643 | schedule = dag_params.get("schedule") |
703 | | - if DagBuilder._is_asset(schedule): |
704 | | - dag_kwargs["schedule"] = DagBuilder._asset_schedule(schedule) |
| 644 | + if ( |
| 645 | + utils.check_dict_key(dag_params, "schedule") |
| 646 | + and isinstance(dag_params["schedule"], str) |
| 647 | + and dag_params["schedule"].strip().lower() == "none" |
| 648 | + ): |
| 649 | + dag_kwargs["schedule"] = None |
705 | 650 | else: |
706 | | - if ( |
707 | | - utils.check_dict_key(dag_params, "schedule") |
708 | | - and isinstance(dag_params["schedule"], str) |
709 | | - and dag_params["schedule"].strip().lower() == "none" |
710 | | - ): |
711 | | - dag_kwargs["schedule"] = None |
712 | | - else: |
713 | | - dag_kwargs["schedule"] = schedule |
| 651 | + dag_kwargs["schedule"] = schedule |
714 | 652 |
|
715 | 653 | @staticmethod |
716 | 654 | def _normalise_tasks_config(tasks_cfg: Any) -> Dict[str, Dict[str, Any]]: |
|
0 commit comments