Skip to content

utils

send_to_channel_sync(cur, group_key, message, expire, channel=None)

Source code in tasks/utils.py
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
def send_to_channel_sync(cur, group_key, message, expire, channel=None):
    if channel is None:
        channels = _retrieve_group_channels(cur, group_key)
    else:
        channels = [channel]

    values_str = b','.join(
        cur.mogrify(
            "(%s, %s, (NOW() + INTERVAL '%s seconds'))", (channel, message, expire)
        ) for channel in channels
    )
    insert_message_sql = (
        b'INSERT INTO channels_postgres_message (channel, message, expire) VALUES ' + values_str
    )
    cur.execute(insert_message_sql)

send_to_group_sync(group, message)

Source code in tasks/utils.py
38
39
40
41
42
43
44
45
46
47
48
def send_to_group_sync(group, message):
    channel_layer: PostgresChannelLayer = get_channel_layer()

    assert channel_layer.valid_group_name(group), "Group name not valid"
    group_key = channel_layer._group_key(group)
    message = channel_layer.serialize(message)
    cur = connection.cursor()

    send_to_channel_sync(
        cur, group_key, message, channel_layer.expiry
    )