Installation¶
In order to use Sisy, you must first install Channels. Once you have it up and running, proceed with the steps below. If you haven’t used Channels before, you may want to look through some of the Channels docs, including Channels Concepts and the Getting Started guide.
Install Sisy from PyPI:
pip install -U sisy
Add Sisy to your
INSTALLED_APPS
list:INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'channels', 'sisy.apps.SisyConfig', ]
Add Sisy’s routing to your
routing.py
file:1 2 3 4 5 6 7 8
from channels.routing import route, include channel_routing = [ include('sisy.routing.channel_routing'), # route("websocket.connect", ws_add), # route("websocket.receive", ws_message), # route("websocket.disconnect", ws_disconnect), ]
Make sure there is at least one worker running which listens to the channels that Sisy sends its messages on (see Project Settings below).
Start the
sisy_heartbeat
management command to provide the heartbeat messages to Sisy. This can be easily run alongsidedaphne
as it uses very little in terms of CPU load.Now you can start using Sisy.
Project settings¶
All of these settings are optional. If you already have an existing django/channels project, you probably already have a channel name scheme. You can adjust Sisy’s names to fit your pattern with these settings, if necessary. You can also adjust the frequency of the “clock tick” messages that Sisy sends to its scheduling code.
SISY_HEARTBEAT_CHANNEL
(default: sisy.heartbeat
)
(string) Provides the channel name for Sisy to use for the heartbeat messages.
SISY_RUN_TASK_CHANNEL
(default: sisy.run_task
)
(string) Provides the channel name for Sisy to run the tasks on a worker.
SISY_KILL_TASK_CHANNEL
(default: sisy.kill_task
)
(string) Provides the channel name for Sisy to run the task reaper (to kill completed tasks.)
SISY_HEARTBEAT_FREQUENCY
(default: 60
)
(integer) Determines the frequency (in seconds) of Sisy’s heartbeat messages. This sets the bound on task frequency; no task can execute more frequently than this setting. Consequently, if you need more frequent task runs, set this lower (probably not lower than about 5, as Sisy is not designed to handle very high frequency tasks) and add the optional sixth field to your frequently-called task’s schedule, to specify the seconds; e.g.* * * * * */30
will make the task eligible for execution every thirty seconds.
SISY_DEFAULT_SCHEDULE
(default: '* * * * *'
)
(string) Provides the default cron schedule for Sisy’s tasks. The default causes the task to run once per minute.