mirror of
https://github.com/fergalmoran/dss.api.git
synced 2026-01-30 04:15:08 +00:00
Initial 10 second schedule
This commit is contained in:
@@ -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')
|
||||
|
||||
10
spa/tasks.py
10
spa/tasks.py
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user