|
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 |
@@ -592,66 +593,6 @@ def process_file_with_datasets(file: str, datasets_conditions: str) -> Any: |
592 | 593 | datasets_uri = utils.get_datasets_uri_yaml_file(file, list(dataset_map.keys())) |
593 | 594 | return [Dataset(uri) for uri in datasets_uri] |
594 | 595 |
|
595 | | - @staticmethod |
596 | | - def _init_watchers(watchers_data): |
597 | | - """Initialize watcher objects from configuration.""" |
598 | | - from dagfactory.utils import _import_from_string |
599 | | - |
600 | | - watchers = [] |
601 | | - for watcher in watchers_data: |
602 | | - watcher_class = _import_from_string(watcher["callable"]) |
603 | | - trigger_data = watcher.get("trigger", {}) |
604 | | - trigger_class = _import_from_string(trigger_data.get("callable")) |
605 | | - trigger_params = trigger_data.get("params", {}) |
606 | | - watchers.append(watcher_class(name=watcher.get("name"), trigger=trigger_class(**trigger_params))) |
607 | | - return watchers |
608 | | - |
609 | | - @staticmethod |
610 | | - def _combine_assets(assets, op: str): |
611 | | - """Combine a list of Asset objects using logical operators.""" |
612 | | - if op == "or": |
613 | | - return reduce(lambda a, b: a | b, assets) |
614 | | - elif op == "and": |
615 | | - return reduce(lambda a, b: a & b, assets) |
616 | | - else: |
617 | | - raise ValueError(f"Unknown operator: {op}") |
618 | | - |
619 | | - @staticmethod |
620 | | - def _is_asset(d): |
621 | | - from airflow.sdk import Asset |
622 | | - |
623 | | - if not isinstance(d, dict): |
624 | | - return False |
625 | | - for key, value in d.items(): |
626 | | - if isinstance(value, Asset): |
627 | | - return True |
628 | | - elif isinstance(value, list): |
629 | | - if any(isinstance(item, Asset) for item in value): |
630 | | - return True |
631 | | - elif isinstance(value, dict): |
632 | | - if DagBuilder._is_asset(value): |
633 | | - return True |
634 | | - return False |
635 | | - |
636 | | - @staticmethod |
637 | | - def _asset_schedule(value): |
638 | | - """Recursively parse and construct assets or combinations of assets.""" |
639 | | - from airflow.sdk import Asset |
640 | | - |
641 | | - if isinstance(value, dict): |
642 | | - if "or" in value: |
643 | | - assets = [DagBuilder._asset_schedule(item) for item in value["or"]] |
644 | | - return DagBuilder._combine_assets(assets, "or") |
645 | | - elif "and" in value: |
646 | | - assets = [DagBuilder._asset_schedule(item) for item in value["and"]] |
647 | | - return DagBuilder._combine_assets(assets, "and") |
648 | | - elif isinstance(value, list): |
649 | | - return [asset for asset in value] |
650 | | - elif isinstance(value, Asset): |
651 | | - return value |
652 | | - else: |
653 | | - raise TypeError(f"Unexpected data type: {type(value)}") |
654 | | - |
655 | 596 | @staticmethod |
656 | 597 | def configure_schedule(dag_params: Dict[str, Any], dag_kwargs: Dict[str, Any]) -> None: |
657 | 598 | """ |
@@ -722,19 +663,11 @@ def configure_schedule(dag_params: Dict[str, Any], dag_kwargs: Dict[str, Any]) - |
722 | 663 | if has_datasets_attr: |
723 | 664 | schedule.pop("datasets") |
724 | 665 | else: |
725 | | - if "schedule" in dag_params: |
726 | | - schedule = dag_params.get("schedule") |
727 | | - if DagBuilder._is_asset(schedule): |
728 | | - dag_kwargs[schedule_key] = DagBuilder._asset_schedule(schedule) |
729 | | - else: |
730 | | - if ( |
731 | | - utils.check_dict_key(dag_params, "schedule") |
732 | | - and isinstance(dag_params["schedule"], str) |
733 | | - and dag_params["schedule"].strip().lower() == "none" |
734 | | - ): |
735 | | - dag_kwargs[schedule_key] = None |
736 | | - else: |
737 | | - dag_kwargs[schedule_key] = schedule |
| 666 | + schedule = dag_params.get("schedule") |
| 667 | + if utils.check_dict_key(dag_params, "schedule") and isinstance(schedule, str) and schedule.strip().lower() == "none": |
| 668 | + dag_kwargs[schedule_key] = None |
| 669 | + else: |
| 670 | + dag_kwargs[schedule_key] = dag_params.get("schedule") |
738 | 671 |
|
739 | 672 | @staticmethod |
740 | 673 | def _normalise_tasks_config(tasks_cfg: Any) -> Dict[str, Dict[str, Any]]: |
|
0 commit comments