daphne/docs/delay.rst
Sam Bolgert 3dddefa845 Delay Protocol Server (#401)
* Add Delay Protocol Server

Add a process that listens to a specific channel
and delays incoming messages by a given time.

* Add custom django command rundelay
* Add test suite
* Implements #115

* Add channels.delay app

* Add AppConfig

* Move rundelay command to channels.delay app

* Refactor DelayedMessage into model

Move login into a database backed model.
* Update Worker
* Add migration

* Add delay docs page

* Add to TOC

* Fix import sorting

* Add ASGI spec document for Delay Protocol

* Update channels.delay doc with new channel name
* remove interval docs

* Refactor Delay to use milliseconds instead of seconds

Use milliseconds as the default unit. Gives more control to developers.

* Remove interval logic from DelayedMessage
* Remove interval tests
* Tweak test logic to use milliseconds
2016-11-24 10:54:03 -08:00

47 lines
1.1 KiB
ReStructuredText

Delay Server
============
Channels has an optional app ``channels.delay`` that implements the :doc:`ASGI Delay Protocol <asgi/delay>`.
The server is exposed through a custom management command ``rundelay`` which listens to
the `asgi.delay` channel for messages to delay.
Getting Started with Delay
==========================
To Install the app add `channels.delay` to `INSTALLED_APPS`::
INSTALLED_APPS = (
...
'channels',
'channels.delay'
)
Run `migrate` to create the tables
`python manage.py migrate`
Run the delay process to start processing messages
`python manage.py rundelay`
Now you're ready to start delaying messages.
Delaying Messages
=================
To delay a message by a fixed number of milliseconds use the `delay` parameter.
Here's an example::
from channels import Channel
delayed_message = {
'channel': 'example_channel',
'content': {'x': 1},
'delay': 10 * 1000
}
# The message will be delayed 10 seconds by the server and then sent
Channel('asgi.delay').send(delayed_message, immediately=True)