Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rajasimon/beatserver
Beatserver, a periodic task scheduler for Django 🎵
https://github.com/rajasimon/beatserver
channels django django-channels python scheduler task websocket
Last synced: 4 months ago
JSON representation
Beatserver, a periodic task scheduler for Django 🎵
- Host: GitHub
- URL: https://github.com/rajasimon/beatserver
- Owner: rajasimon
- License: mit
- Created: 2016-07-18T18:36:16.000Z (over 8 years ago)
- Default Branch: main
- Last Pushed: 2022-12-04T19:02:38.000Z (about 2 years ago)
- Last Synced: 2024-10-14T04:45:56.041Z (4 months ago)
- Topics: channels, django, django-channels, python, scheduler, task, websocket
- Language: Python
- Homepage: https://rajasimon.io/django-channels-background-task/
- Size: 164 KB
- Stars: 141
- Watchers: 8
- Forks: 20
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- -awesome-django - beatserver - A periodic task scheduler for Django. (Third-Party Packages / Task Queues)
- awesome-django - beatserver - A periodic task scheduler for Django. (Third-Party Packages / Task Queues)
README
# Beat Server
[![Build Status](https://travis-ci.org/rajasimon/beatserver.svg?branch=master)](https://travis-ci.org/rajasimon/beatserver)
[![PyPI version](https://badge.fury.io/py/beatserver.svg)](https://badge.fury.io/py/beatserver)Beatserver, a periodic task scheduler for django channels | beta software
### How to install
#### Prerequirements:
Follow django channels documentation on howto install channels.
#### Install beatserver:
```shell
pip install -U beatserver
```### Configurations:
Add `beatserver` to `INSTALLED_APPS` in **settings.py**:
```python
INSTALLED_APPS = [
'beatserver',
'channels',
'...'
]
```**beatconfig.py**
```python
from datetime import timedeltaBEAT_SCHEDULE = {
'testing-print': [
{
# will call test_print method of PrintConsumer
'type': 'test.print',
# message to pass to the consumer
'message': {'testing': 'one'},
# Every 5 seconds
'schedule': timedelta(seconds=5)
},
{
'type': 'test.print',
'message': {'testing': 'two'},
# Precisely at 3AM on Monday
'schedule': '0 3 * * 1'
},
]
}
```Schedules can be specified as timedeltas for running tasks on specified intervals, or as cron-syntax strings for running tasks on exact schedules.
**routing.py**
```python
application = ProtocolTypeRouter({
"channel": ChannelNameRouter({
"testing-print": PrintConsumer,
}),
})
```**consumers.py**
```python
from channels.consumer import SyncConsumerclass PrintConsumer(SyncConsumer):
def test_print(self, message):
print(message)
```### How to run:
```shell
python manage.py beatserver
```