Пример #1
0
def dag_update(dag_id):
    args = dagCliArgs(dag_id, 'dags')
    try:
        dag = cli_get_dag(args)
    except AirflowException:
        return ApiResponse.not_found(
            'Could not find a dag with ID {}'.format(dag_id))
    logging.info("Processing dag {} PUT body {}".format(
        dag_id, request.get_json()))
    body = request.get_json()
    if body is None or 'is_active' not in body:
        return ApiResponse.bad_request(
            "A Json body with 'is_active': True/False is expected")

    try:
        if body['is_active']:
            unpause(None, dag)
        elif not body['is_active']:
            pause(None, dag)
    except AirflowException:
        return ApiResponse.not_found(
            'Could not pause/unpause dag with ID {}'.format(dag_id))

    payload = {
        'dag_id': dag_id,
        'full_path': dag.full_filepath,
        'is_active': (not dag.is_paused),
        'last_execution': str(dag.latest_execution_date)
    }

    return ApiResponse.success(payload)
Пример #2
0
    def test_pause(self):
        args = self.parser.parse_args([
            'dags', 'pause', 'example_bash_operator'])
        cli.pause(args)
        self.assertIn(self.dagbag.dags['example_bash_operator'].is_paused, [True, 1])

        args = self.parser.parse_args([
            'dags', 'unpause', 'example_bash_operator'])
        cli.unpause(args)
        self.assertIn(self.dagbag.dags['example_bash_operator'].is_paused, [False, 0])
Пример #3
0
def unpause_dag(dag):
    """
    Wrapper around airflow.bin.cli.unpause. The issue is when we deploy the airflow dags they don't exist
    in the DagModel yet, so need to check if it exists first and then run the unpause.
    :param dag: DAG object
    """
    session = Session()
    try:
        dm = session.query(DagModel).filter(DagModel.dag_id == dag.dag_id).first()
        if dm:
            unpause(dag.default_args, dag)
    except:
        session.rollback()
    finally:
        session.close()