generates a filter for status==waiting and
    time older than lte_time

def expire_filter(lte_time, conn=None):
    """
    generates a filter for status==waiting and
    time older than lte_time
    """
    if RBO.index_list().contains(IDX_OUTPUT_JOB_ID).run(conn):
        return (r.row[EXPIRE_FIELD] <= lte_time)
    else:
        return (
            (
                (r.row[STATUS_FIELD] == WAITING) |
                (r.row[STATUS_FIELD] == READY)
            ) &
            (r.row[EXPIRE_FIELD] <= lte_time)
        )