def advisory_lock_by_relation_name(self, cursor, rel_name: str):
     """
     Try acquiring a PG advisory lock by an integer identifier matching the specified relation name and exit
     immediately.
     This is equal locking by table name until the transaction ends.
     :param cursor:
     :param rel_name:
     :return:
     """
     sql = SQLClause('''select pg_try_advisory_xact_lock(
                                     (select c.oid id from pg_class c where c.relname = %s limit 1)::integer
                                                        )''', [rel_name])
     return fetch_bool(cursor, sql)
def _send_digest_scheduled(run_date: datetime) -> bool:
    with connection.cursor() as cursor:
        sql = '''select exists(select id from task_task 
        where name = %s and (kwargs->>'run_date')::timestamptz = %s)'''
        return fetch_bool(cursor, SQLClause(sql, [SendDigest.name, run_date]))