ASGI implemented as a Twisted resource
Project description
txasgiresource
==============
txasgiresource is `ASGI <http://channels.readthedocs.io/en/latest/asgi.html>`_ implemented as a Twisted Web Resource,
very similar to `WSGIResource <http://twistedmatrix.com/documents/current/api/twisted.web.wsgi.WSGIResource.html>`_.
This is inspired by `Daphne <https://github.com/django/daphne/>`_ but largely implemented from specs.
It can also run as a daemon with or without the actual application embedded inside.
The code is available on `GitHub <https://github.com/JohnDoee/txasgiresource>`_
Usage
-----
As Twisted Resource
~~~~~~~~~~~~~~~~~~~
.. code-block:: python
from twisted.web import server
from yourdjangoproject.asgi import channel_layer
resource = ASGIResource(channel_layer)
site = server.Site(resource)
# If we are done with the resource, make sure to stop it.
resource.stop()
As ASGI Protocol server
~~~~~~~~~~~~~~~~~~~~~~~
::
twistd -n txasgi -c yourdjangoproject.asgi:channel_layer
As ASGI Protocol server with embedded workers
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
::
twistd -n txasgi -c yourdjangoproject.asgi:channel_layer -w 6
As ASGI Protocol server with embedded workers and on a different port and ip
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
::
twistd -n txasgi -c yourdjangoproject.asgi:channel_layer -w 6 -d tcp:5566:interface=0.0.0.0
Scheduler
---------
The scheduler is built around `apscheduler <http://apscheduler.readthedocs.io/>`_ and directly maps
to the three schedule-types:
- `cron <http://apscheduler.readthedocs.io/en/latest/modules/triggers/cron.html>`_,
- `interval <http://apscheduler.readthedocs.io/en/latest/modules/triggers/interval.html>`_
- `date <http://apscheduler.readthedocs.io/en/latest/modules/triggers/date.html>`_.
Schedule a job
.. code-block:: python
Channel('schedule').send({
'method': 'add',
'id': 'some_unique_job_id',
'reply_channel': 'schedule.time_to_run',
'reply_args': {'some', 'reply'},
'trigger': 'date',
'run_date': '2009-11-06 16:30:05',
})
Setup channel for the reply
.. code-block:: python
channel_routing = {
'schedule.time_to_run': 'myapp.consumers.my_consumer',
}
Cancel the job
.. code-block:: python
Channel('schedule').send({
'method': 'remove',
'id': 'some_unique_job_id',
})
Status
------
Master branch
~~~~~~~~~~~~~~
.. image:: https://coveralls.io/repos/github/JohnDoee/txasgiresource/badge.svg?branch=master
:target: https://coveralls.io/github/JohnDoee/txasgiresource?branch=master
.. image:: https://travis-ci.org/JohnDoee/txasgiresource.svg?branch=master
:target: https://travis-ci.org/JohnDoee/txasgiresource
Develop branch
~~~~~~~~~~~~~~
.. image:: https://coveralls.io/repos/github/JohnDoee/txasgiresource/badge.svg?branch=develop
:target: https://coveralls.io/github/JohnDoee/txasgiresource?branch=develop
.. image:: https://travis-ci.org/JohnDoee/txasgiresource.svg?branch=develop
:target: https://travis-ci.org/JohnDoee/txasgiresource
License
-------
MIT, see LICENSE
==============
txasgiresource is `ASGI <http://channels.readthedocs.io/en/latest/asgi.html>`_ implemented as a Twisted Web Resource,
very similar to `WSGIResource <http://twistedmatrix.com/documents/current/api/twisted.web.wsgi.WSGIResource.html>`_.
This is inspired by `Daphne <https://github.com/django/daphne/>`_ but largely implemented from specs.
It can also run as a daemon with or without the actual application embedded inside.
The code is available on `GitHub <https://github.com/JohnDoee/txasgiresource>`_
Usage
-----
As Twisted Resource
~~~~~~~~~~~~~~~~~~~
.. code-block:: python
from twisted.web import server
from yourdjangoproject.asgi import channel_layer
resource = ASGIResource(channel_layer)
site = server.Site(resource)
# If we are done with the resource, make sure to stop it.
resource.stop()
As ASGI Protocol server
~~~~~~~~~~~~~~~~~~~~~~~
::
twistd -n txasgi -c yourdjangoproject.asgi:channel_layer
As ASGI Protocol server with embedded workers
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
::
twistd -n txasgi -c yourdjangoproject.asgi:channel_layer -w 6
As ASGI Protocol server with embedded workers and on a different port and ip
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
::
twistd -n txasgi -c yourdjangoproject.asgi:channel_layer -w 6 -d tcp:5566:interface=0.0.0.0
Scheduler
---------
The scheduler is built around `apscheduler <http://apscheduler.readthedocs.io/>`_ and directly maps
to the three schedule-types:
- `cron <http://apscheduler.readthedocs.io/en/latest/modules/triggers/cron.html>`_,
- `interval <http://apscheduler.readthedocs.io/en/latest/modules/triggers/interval.html>`_
- `date <http://apscheduler.readthedocs.io/en/latest/modules/triggers/date.html>`_.
Schedule a job
.. code-block:: python
Channel('schedule').send({
'method': 'add',
'id': 'some_unique_job_id',
'reply_channel': 'schedule.time_to_run',
'reply_args': {'some', 'reply'},
'trigger': 'date',
'run_date': '2009-11-06 16:30:05',
})
Setup channel for the reply
.. code-block:: python
channel_routing = {
'schedule.time_to_run': 'myapp.consumers.my_consumer',
}
Cancel the job
.. code-block:: python
Channel('schedule').send({
'method': 'remove',
'id': 'some_unique_job_id',
})
Status
------
Master branch
~~~~~~~~~~~~~~
.. image:: https://coveralls.io/repos/github/JohnDoee/txasgiresource/badge.svg?branch=master
:target: https://coveralls.io/github/JohnDoee/txasgiresource?branch=master
.. image:: https://travis-ci.org/JohnDoee/txasgiresource.svg?branch=master
:target: https://travis-ci.org/JohnDoee/txasgiresource
Develop branch
~~~~~~~~~~~~~~
.. image:: https://coveralls.io/repos/github/JohnDoee/txasgiresource/badge.svg?branch=develop
:target: https://coveralls.io/github/JohnDoee/txasgiresource?branch=develop
.. image:: https://travis-ci.org/JohnDoee/txasgiresource.svg?branch=develop
:target: https://travis-ci.org/JohnDoee/txasgiresource
License
-------
MIT, see LICENSE
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Close
Hashes for txasgiresource-0.2.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cff0202f56335241421b7a1a1882fb65dc767a86abc02bad1e79e787c2589e8c |
|
MD5 | c696ae6d45a71b43ef07fe5f7dd9fffe |
|
BLAKE2b-256 | be0fd8c007a478a5e6f695b7f3ab23cf2a078a60f565bb1086e65824d86c9a09 |