--- /dev/null
+from __future__ import absolute_import
+
+import os
+
+from celery import Celery
+
+from django.conf import settings
+
+# set the default Django settings module for the 'celery' program.
+os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings')
+
+app = Celery('sandbox')
+
+# Using a string here means the worker will not have to
+# pickle the object when using Windows.
+app.config_from_object('django.conf:settings')
+app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
+app.conf.update(
+ CELERY_RESULT_BACKEND='djcelery.backends.database:DatabaseBackend',
+)
+
+@app.task(bind=True)
+def debug_task(self):
+ print('Request: {0!r}'.format(self.request))
# Django settings for server project.
-
DEBUG = True
TEMPLATE_DEBUG = DEBUG
# See https://docs.djangoproject.com/en/1.4/ref/settings/#allowed-hosts
ALLOWED_HOSTS = []
+# SECURITY WARNING: keep the secret key used in production secret!
+SECRET_KEY = 'ghv8us2587n97dq&w$c((o5rj_$-9#d-8j#57y_a9og8wux1h7'
+
# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
'timeside.server',
'timeside.player',
'rest_framework',
- 'django_gearman',
+ 'djcelery',
)
# A sample logging configuration. The only tangible logging
}
# One or more gearman servers
-GEARMAN_SERVERS = ['127.0.0.1']
+# GEARMAN_SERVERS = ['127.0.0.1']
+
+BROKER_URL = 'amqp://guest:guest@localhost//'
+
+
+# This will make sure the app is always imported when
+# Django starts so that shared_task will use this app.
+CELERY_IMPORTS = ("timeside.server.tasks", )
+from celery_app import app
+++ /dev/null
-
-from __future__ import absolute_import
-
-from celery import Celery
-
-app = Celery('timeside',
- broker='amqp://',
- backend='amqp://',
- include=['timeside.tasks'])
-
-# Optional configuration, see the application user guide.
-app.conf.update(
- CELERY_TASK_RESULT_EXPIRES=3600,
-)
-
-if __name__ == '__main__':
- app.start()
def run(sender, **kwargs):
+ from timeside.server.tasks import task_run
instance = kwargs['instance']
if instance.status == _PENDING:
- from django_gearman import GearmanClient
- client = GearmanClient()
- completed_job_request = client.submit_job("timeside.server.task_run", instance.id)
- print "Result: '%s'" % completed_job_request.result
- # instance.run()
+ task_run.delay(instance.id)
post_save.connect(set_mimetype, sender=Item)
-
from __future__ import absolute_import
-from timeside.server.celery import app
+from celery import shared_task
+from .models import Task
+
+
+@shared_task
+def task_run(id):
+ task = Task.objects.get(id=id)
+ task.run()
+
+
+@shared_task
+def add(x, y):
+ return x + y
+
+
+@shared_task
+def mul(x, y):
+ return x * y
-@app.task
-def process(pipe):
- pipe.run()
+@shared_task
+def xsum(numbers):
+ return sum(numbers)
\ No newline at end of file