Example #1
0
    def create_r_config(self, ids, session):

        rows = session.query(FailedDagRun).filter(
            FailedDagRun.id.in_(ids)).all()

        r_obj = {}

        for d in rows:
            if r_obj.__contains__(d.dag_id):
                if not (r_obj[d.dag_id]).__contains__(d.execution_date):
                    r_obj[d.dag_id].append(str(d.execution_date))
            else:
                r_obj[d.dag_id] = [str(d.execution_date)[:19]]

        Variable.set(key='r_config', value=json.dumps(r_obj))

        for id in ids:
            execution_date = session.query(FailedDagRun).filter(
                FailedDagRun.id == id).one().execution_date
            dag_id = session.query(FailedDagRun).filter(
                FailedDagRun.id == id).one().dag_id

            session.query(FailedDagRun).filter(FailedDagRun.id == id).update(
                {'state': 'recovery_executed'}, synchronize_session='fetch')
            Variable.delete(
                key="{}${}".format(str(execution_date)[:19], dag_id))
Example #2
0
    def trigger_dag(self, ids, session=None):

        rows = session.query(FailedDagRun).filter(
            FailedDagRun.id.in_(ids)).all()

        try:
            r_config = Variable.get(key='r_config')
            r_obj = json.loads(r_config)

            for d in rows:
                if r_obj.__contains__(d.dag_id):
                    if not (r_obj[d.dag_id]).__contains__(
                            str(d.execution_date)[:19]):
                        r_obj[d.dag_id].append(str(d.execution_date)[:19])
                    else:
                        pass
                else:
                    r_obj[d.dag_id] = [str(d.execution_date)[:19]]

            Variable.set(key='r_config', value=json.dumps(r_obj))

            for id in ids:
                execution_date = session.query(FailedDagRun).filter(
                    FailedDagRun.id == id).one().execution_date
                dag_id = session.query(FailedDagRun).filter(
                    FailedDagRun.id == id).one().dag_id

                session.query(FailedDagRun).filter(
                    FailedDagRun.id == id).update(
                        {'state': 'recovery_executed'},
                        synchronize_session='fetch')
                Variable.delete(
                    key="{}${}".format(str(execution_date)[:19], dag_id))

        except KeyError as e:
            LoggingMixin().log.warn(e.__str__())
            Variable.set(key='r_config', value='{}')
            self.create_r_config(ids, session)