'Returns a boolean indicating whether the concurrency limit for this DAG
has been reached'

@property
@provide_session
def concurrency_reached(self, session=None):

    TI = TaskInstance
    qry = session.query(func.count(TI.task_id)).filter((TI.dag_id == self.dag_id), TI.task_id.in_(self.task_ids), (TI.state == State.RUNNING))
    return (qry.scalar() >= self.concurrency)
