Initial 10 second schedule

This commit is contained in:
Fergal Moran
2015-09-20 17:25:00 +01:00
parent 086fac87bc
commit 261e547202
2 changed files with 18 additions and 2 deletions

View File

@@ -1,9 +1,9 @@
import os
import logging
from celery import Celery
from celery.schedules import crontab
from spa import tasks
logger = logging.getLogger('dss')
@@ -17,3 +17,9 @@ app = Celery('dss')
# pickle the object when using Windows.
app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
@app.on_after_configure.connect
def setup_periodic_tasks(sender, **kwargs):
# Calls test('hello') every 10 seconds.
sender.add_periodic_task(10.0, tasks.play_pending_audio.s('hello'), name='add every 10')

View File

@@ -1,9 +1,11 @@
from celery.task import task
import os
import logging
import requests
from core.realtime import activity
from core.utils import cdn
from spa.models import Mix
from spa.signals import waveform_generated_signal
try:
@@ -61,3 +63,11 @@ def update_geo_info_task(ip_address, profile_id):
def notify_subscriber(session_id, uid):
if session_id is not None:
activity.post_activity('user:process', session_id, {'type': 'waveform', 'target': uid})
@task
def play_pending_audio():
m = Mix.objects.order_by('uid').first()
print("Playing: {}".format(m.title))
r = requests.post('http://localhost:8888/a/play', data={'audio_file:': m.get_stream_url()})
print(r.text)