コード例 #1
0
    def test_get_dags(self):
        dags = cli.get_dags(None, "example_subdag_operator")
        self.assertEqual(len(dags), 1)

        dags = cli.get_dags(None, "subdag", True)
        self.assertGreater(len(dags), 1)

        with self.assertRaises(AirflowException):
            cli.get_dags(None, "foobar", True)
コード例 #2
0
ファイル: test_cli_util.py プロジェクト: ysktir/airflow-1
    def test_get_dags(self):
        dags = cli.get_dags(None, "example_subdag_operator")
        assert len(dags) == 1

        dags = cli.get_dags(None, "subdag", True)
        assert len(dags) > 1

        with pytest.raises(AirflowException):
            cli.get_dags(None, "foobar", True)
コード例 #3
0
    def test_get_dags(self):
        parser = CLIFactory.get_parser()
        dags = cli.get_dags(
            parser.parse_args(
                ['tasks', 'clear', 'example_subdag_operator', '--yes']))
        self.assertEqual(len(dags), 1)

        dags = cli.get_dags(
            parser.parse_args(['tasks', 'clear', 'subdag', '-dx', '--yes']))
        self.assertGreater(len(dags), 1)

        with self.assertRaises(AirflowException):
            cli.get_dags(
                parser.parse_args(['tasks', 'clear', 'foobar', '-dx',
                                   '--yes']))
コード例 #4
0
ファイル: task_command.py プロジェクト: folly3/airflow-1
def task_clear(args):
    """Clears all task instances or only those matched by regex for a DAG(s)"""
    logging.basicConfig(
        level=settings.LOGGING_LEVEL,
        format=settings.SIMPLE_LOG_FORMAT)

    if args.dag_id and not args.subdir and not args.dag_regex and not args.task_regex:
        dags = get_dag_by_file_location(args.dag_id)
    else:
        # todo clear command only accepts a single dag_id. no reason for get_dags with 's' except regex?
        dags = get_dags(args.subdir, args.dag_id, use_regex=args.dag_regex)

        if args.task_regex:
            for idx, dag in enumerate(dags):
                dags[idx] = dag.sub_dag(
                    task_regex=args.task_regex,
                    include_downstream=args.downstream,
                    include_upstream=args.upstream)

    DAG.clear_dags(
        dags,
        start_date=args.start_date,
        end_date=args.end_date,
        only_failed=args.only_failed,
        only_running=args.only_running,
        confirm_prompt=not args.yes,
        include_subdags=not args.exclude_subdags,
        include_parentdag=not args.exclude_parentdag,
    )
コード例 #5
0
def task_clear(args):
    """Clears all task instances or only those matched by regex for a DAG(s)"""
    logging.basicConfig(level=settings.LOGGING_LEVEL,
                        format=settings.SIMPLE_LOG_FORMAT)
    dags = get_dags(args)

    if args.task_regex:
        for idx, dag in enumerate(dags):
            dags[idx] = dag.sub_dag(task_regex=args.task_regex,
                                    include_downstream=args.downstream,
                                    include_upstream=args.upstream)

    DAG.clear_dags(
        dags,
        start_date=args.start_date,
        end_date=args.end_date,
        only_failed=args.only_failed,
        only_running=args.only_running,
        confirm_prompt=not args.yes,
        include_subdags=not args.exclude_subdags,
        include_parentdag=not args.exclude_parentdag,
    )
コード例 #6
0
def dag_backfill(args, dag=None):
    """Creates backfill job or dry run for a DAG or list of DAGs using regex"""
    logging.basicConfig(level=settings.LOGGING_LEVEL, format=settings.SIMPLE_LOG_FORMAT)

    signal.signal(signal.SIGTERM, sigint_handler)

    import warnings

    warnings.warn(
        '--ignore-first-depends-on-past is deprecated as the value is always set to True',
        category=PendingDeprecationWarning,
    )

    if args.ignore_first_depends_on_past is False:
        args.ignore_first_depends_on_past = True

    if not args.start_date and not args.end_date:
        raise AirflowException("Provide a start_date and/or end_date")

    if not dag:
        dags = get_dags(args.subdir, dag_id=args.dag_id, use_regex=args.treat_dag_as_regex)
    else:
        dags = dag if type(dag) == list else [dag]

    dags.sort(key=lambda d: d.dag_id)

    # If only one date is passed, using same as start and end
    args.end_date = args.end_date or args.start_date
    args.start_date = args.start_date or args.end_date

    run_conf = None
    if args.conf:
        run_conf = json.loads(args.conf)

    for dag in dags:
        if args.task_regex:
            dag = dag.partial_subset(
                task_ids_or_regex=args.task_regex, include_upstream=not args.ignore_dependencies
            )
            if not dag.task_dict:
                raise AirflowException(
                    f"There are no tasks that match '{args.task_regex}' regex. Nothing to run, exiting..."
                )

        if args.dry_run:
            print(f"Dry run of DAG {dag.dag_id} on {args.start_date}")
            dr = DagRun(dag.dag_id, execution_date=args.start_date)
            for task in dag.tasks:
                print(f"Task {task.task_id} located in DAG {dag.dag_id}")
                ti = TaskInstance(task, run_id=None)
                ti.dag_run = dr
                ti.dry_run()
        else:
            if args.reset_dagruns:
                DAG.clear_dags(
                    [dag],
                    start_date=args.start_date,
                    end_date=args.end_date,
                    confirm_prompt=not args.yes,
                    include_subdags=True,
                    dag_run_state=DagRunState.QUEUED,
                )

            try:
                dag.run(
                    start_date=args.start_date,
                    end_date=args.end_date,
                    mark_success=args.mark_success,
                    local=args.local,
                    donot_pickle=(args.donot_pickle or conf.getboolean('core', 'donot_pickle')),
                    ignore_first_depends_on_past=args.ignore_first_depends_on_past,
                    ignore_task_deps=args.ignore_dependencies,
                    pool=args.pool,
                    delay_on_limit_secs=args.delay_on_limit,
                    verbose=args.verbose,
                    conf=run_conf,
                    rerun_failed_tasks=args.rerun_failed_tasks,
                    run_backwards=args.run_backwards,
                    continue_on_failures=args.continue_on_failures,
                )
            except ValueError as vr:
                print(str(vr))
                sys.exit(1)

    if len(dags) > 1:
        log.info("All of the backfills are done.")