Commit b5ba0825 by Chif Gergő

Test polling works

parent a587ac4e
Pipeline #1084 failed with stage
in 2 minutes 24 seconds
from __future__ import absolute_import, unicode_literals
# This will make sure the app is always imported when
# Django starts so that shared_task will use this app.
from .celery import app as celery_app
__all__ = ('celery_app',)
......@@ -5,15 +5,17 @@ import os
from celery import Celery
# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'proj.settings')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'recircle.settings.base')
app = Celery('proj')
app = Celery('recircle')
# Using a string here means the worker doesn't have to serialize
# 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.base', 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,17 @@ app.autodiscover_tasks()
@app.task(bind=True)
def debug_task(self):
print('Request: {0!r}'.format(self.request))
# Testing the periodic tasks
@app.on_after_configure.connect
def setup_periodic_tasks(sender, **kwargs):
# Calls test('hello') every 10 seconds.
sender.add_periodic_task(10.0, test.s('hello'), name='add every 10')
@app.task
def test(arg):
from instance.models import Instance
for instance in Instance.objects.all():
instance.update_status()
......@@ -43,7 +43,8 @@ INSTALLED_APPS = [
"corsheaders",
"guardian",
"django_nose",
"channels"
"channels",
"django_celery_beat",
]
LOCAL_APPS = [
......@@ -243,6 +244,8 @@ AUTHENTICATION_BACKENDS = (
'guardian.backends.ObjectPermissionBackend',
)
# Channels settings
CHANNEL_LAYERS = {
'default': {
'BACKEND': 'channels_redis.core.RedisChannelLayer',
......@@ -253,3 +256,7 @@ CHANNEL_LAYERS = {
}
ASGI_APPLICATION = "recircle.routing.application"
# Celery settings
CELERY_BROKER_URL = "redis://localhost:6379/0"
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