Commit 74faf9bc by Chif Gergő

Create task to status polling

parent a587ac4e
......@@ -13,7 +13,9 @@ app = Celery('proj')
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys
# should have a `CELERY_` prefix.
app.config_from_object('django.conf:settings', namespace='CELERY')
# app.config_from_object('django.conf:settings', namespace='CELERY')
app.conf.broker_url = 'redis://localhost:6379/0'
# Load task modules from all registered Django app configs.
app.autodiscover_tasks()
......@@ -22,3 +24,11 @@ app.autodiscover_tasks()
@app.task(bind=True)
def debug_task(self):
print('Request: {0!r}'.format(self.request))
app.conf.beat_schedule = {
'polling-status-in-every-second': {
'task': 'status.tasks.poll_status',
'schedule': 1.0,
},
}
......@@ -30,5 +30,4 @@ class StatusConsumer(WebsocketConsumer):
pass
def status_changed(self, event):
logger.info("Event received")
self.send(text_data=json.dumps({"vm": event["vm"], "status": event["status"]}))
from celery import shared_task
@shared_task
def poll_status():
from instance.models import Instance
for instance in Instance.objects.filter(deleted=False):
instance.update_status()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment