djangofloor.tasks
¶
Define Celery tasks and functions for calling signals¶
This module is automatically imported by Celery. Use these functions for:
- setting websocket channels allowed for a given
django.http.response.HttpResponse
,- calling signals, with a full function (
djangofloor.tasks.call()
) and a shortcut (djangofloor.tasks.scall()
)
-
class
djangofloor.tasks.
Constant
(name)[source]¶ Allow to define constants that can be nicely printed to stdout
-
djangofloor.tasks.
call
(window_info, signal_name, to=None, kwargs=None, countdown=None, expires=None, eta=None)[source]¶ Call a DjangoFloor signal.
Parameters: - window_info – either a
django.http.request.HttpRequest
or adjangofloor.wsgi.window_info.WindowInfo
- signal_name – name of the called signal (
str
) - to –
list
of the topics that should receive the signal - kwargs – dict with all arguments of your signal. Will be encoded to JSON with settings.WEBSOCKET_SIGNAL_ENCODER and decoded with settings.WEBSOCKET_SIGNAL_DECODER.
- countdown – check the Celery doc (in a nutshell: number of seconds before executing the signal)
- expires – check the Celery doc (in a nutshell: if this signal is not executed before this number of seconds, it is cancelled)
- eta – check the Celery doc (in a nutshell: datetime of running this signal)
- window_info – either a
-
djangofloor.tasks.
df_call
(signal_name, request, sharing=None, from_client=False, kwargs=None, countdown=None, expires=None, eta=None)[source]¶ Deprecated since version 1.0,: do not use it
-
djangofloor.tasks.
get_websocket_redis_connection
()[source]¶ Return a valid Redis connection, using a connection pool.
-
djangofloor.tasks.
import_signals_and_functions
[source]¶ Import all signals.py, ‘forms.py’ and functions.py files to register signals and WS functions (tries these files for all Django apps).
-
djangofloor.tasks.
scall
(window_info, signal_name, to=None, **kwargs)[source]¶ Shortcut to
djangofloor.tasks.call()
, allowing to directly pass arguments of the signal to this function. Your signal cannot use window_info, signal_name and to as argument names.These two successive calls are strictly equivalent:
from djangofloor.tasks import call, scall, WINDOW, SERVER def my_python_view(request): scall(request, 'my.signal.name', to=[WINDOW, SERVER], arg1=12, arg2='Hello') call(request, 'my.signal.name', to=[WINDOW, SERVER], kwargs={'arg1': 12, 'arg2': 'Hello'})
-
djangofloor.tasks.
set_websocket_topics
(request, *topics)[source]¶ Use it in a Django view for setting websocket topics. Any signal sent to one of these topics will be received by the client.
param request: django.http.request.HttpRequest
param topics: list of topics that will be subscribed by the websocket (can be any Python object).