only connect to pandora as needed
This commit is contained in:
parent
43c9849b16
commit
71d6e0d0e6
2 changed files with 17 additions and 2 deletions
|
@ -7,7 +7,6 @@ Restart=always
|
|||
User=dd
|
||||
Group=dd
|
||||
WorkingDirectory=/srv/dd/re
|
||||
ExecStartPre=/usr/bin/wait-for-it -h pandora.dmp -p 80
|
||||
ExecStart=/srv/dd/re/server.py
|
||||
|
||||
[Install]
|
||||
|
|
|
@ -5,18 +5,24 @@ Recommendation Engine Example
|
|||
|
||||
from collections import defaultdict
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import random
|
||||
import time
|
||||
|
||||
import ox
|
||||
|
||||
from utils import run_async
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Engine:
|
||||
_pandora = None
|
||||
|
||||
def __init__(self, path, **kwargs):
|
||||
self.path = path
|
||||
self.pandora = Pandora(
|
||||
self.pandora_args = dict(
|
||||
url=kwargs.get('pandora', 'http://pandora.dmp/api/'),
|
||||
username=kwargs.get('username', 'dd.re'),
|
||||
password=kwargs.get('password', 'dd.re')
|
||||
|
@ -28,6 +34,16 @@ class Engine:
|
|||
else:
|
||||
self.playlists = []
|
||||
|
||||
@property
|
||||
def pandora(self):
|
||||
while not self._pandora:
|
||||
try:
|
||||
self._pandora = Pandora(**self.pandora_args)
|
||||
except:
|
||||
logger.error('failed to connect to pandora, retry in 10 seconds')
|
||||
time.sleep(10)
|
||||
return self._pandora
|
||||
|
||||
def _patch_clips(self, clips):
|
||||
inpoints = {}
|
||||
for index, clip in enumerate(clips):
|
||||
|
|
Loading…
Reference in a new issue