rajasimon / beatserver Goto Github PK
View Code? Open in Web Editor NEWBeatserver, a periodic task scheduler for Django ๐ต
Home Page: https://rajasimon.io/django-channels-background-task/
License: MIT License
Beatserver, a periodic task scheduler for Django ๐ต
Home Page: https://rajasimon.io/django-channels-background-task/
License: MIT License
One of the cool thing about ASGI is we can hook with asyncio loop easily and that allows us to implement background task not just to channels but any ASGI framework. I'm going to invest some time around this year to change the code to support for all the asgi applications.
Hello, first i'd like to thank you for this module.
I would like to have several periodic tasks. I've thought about grouping them in a specific channel? so the would be all together. But as i see in the code, it's about a single task per channel name.
In order to support different message types in one channel, there should be 2 cycles here
beatserver/beatserver/server.py
Line 30 in 58feddc
hey, I need to run 2 different task with beatserver, I use django2.x and channels2.x,
in consumers.py I write a class BeatServer as:
class BeatServer(SyncConsumer):
def task_one(self, message):
print("task 1 #############")
data = {"task_one": "ok"}
room_group_name_one = "room_one"
async_to_sync(self.channel_layer.group_send)(room_group_name_one, {
"type": "chat.message",
"message": data
})
def task_two(self, message):
print("task 2 #############")
data = {"task_two": "ok"}
room_group_name_two = "room_two"
async_to_sync(self.channel_layer.group_send)(room_group_name_two, {
"type": "chat.message",
"message": data
})
and beatconfig.py as below
from datetime import timedelta
BEAT_SCHEDULE = {
'task-one': {
'type': 'task_one',
'message': {'message': 'send successed'},
'schedule': timedelta(seconds=4)
},
'task-two': {
'type': 'task_two',
'message': {'message': 'send successed'},
'schedule': timedelta(seconds=4)
},
}
then run beatserver as python3 manage.py beatserver
I can see task 1 #############
, and things were going well on client
but task two seens not work, i cannot see any tag, and clients can not receive any messages.
and there are no errors raise.
can it be done if more than one tasks with beatserver?
Hello,
As i understand, spinning up the beatserver is done separately from spinning up my django server.
So how would i go about using this in production, if my stack consists of Gunicorn + Daphne (channels and db already configured with redis channel layer )
So for simplicity, lets say that my current deployment script runs this command
sudo systemctl restart gunicorn.service && sudo systemctl restart nginx && sudo systemctl restart daphne.service
and in my gunicorn config my ExecStart
is
gunicorn my_app.wsgi --bind 0.0.0.0:8000 --log-level error --log-file=- --workers 5 --preload
daphne ExecStart
ExecStart=/home/ubuntu/env/bin/daphne --bind 0.0.0.0 --port <my_port> --verbosity 2 my_app.asgi:application
how can i also spin up beatserver to play nice with the others ?
Hey, thanks for the project! I cloned the repo and tried to run the example, but there are no static files, namely, there is no websocketbridge.js
file
After installed with command pip3 install -U beatserver, OS can not recognize command 'beatserver' on OSX.
BTW, beatserver is a websocket server which can continuely send message to clients browser frontend if I didn't make any misunderstanding?
Nice if this project have the examples to play with.
Currently the mentioned task in the beatconfig execute after the schedule time and repeat but that's okay but make it option to execute the task immediate. I think the immediate execution of the task should be in default mode and make it options to the current behaviour.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.