Created
March 29, 2016 18:20
-
-
Save johngrantuk/c9a94e70fcdcb7c306a0748841aa0b5a to your computer and use it in GitHub Desktop.
Django Channels background worker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from channels import Group | |
from django.core.management import BaseCommand | |
import time | |
#The class must be named Command, and subclass BaseCommand | |
class Command(BaseCommand): | |
# Show this when the user types help | |
help = "Simulates reading sensor and sending over Channel." | |
# A command must define handle() | |
def handle(self, *args, **options): | |
x = 0 | |
while True: | |
Group("sensor").send({'text': "Sensor reading=" + str(x)}) | |
time.sleep(2) | |
x = x + 1 | |
self.stdout.write("Sensor reading..." + str(x)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment