work on logging
This commit is contained in:
@ -47,7 +47,7 @@ class Command (BaseCommand):
|
||||
delay = options.get('delay') / 1000
|
||||
while True:
|
||||
for controller in self.monitor.controllers.values():
|
||||
controller.dealer.monitor()
|
||||
controller.monitor()
|
||||
time.sleep(delay)
|
||||
|
||||
|
||||
|
@ -241,13 +241,6 @@ class Dealer (Source):
|
||||
def stream_info (self):
|
||||
pass
|
||||
|
||||
def get_next_diffusion (self):
|
||||
diffusions = models.Diffusion.get_next(self.station)
|
||||
if not diffusions.count():
|
||||
return
|
||||
diffusion = diffusions[0]
|
||||
return diffusion
|
||||
|
||||
@property
|
||||
def on (self):
|
||||
r = self.connector.send('var.get ', self.id, '_on')
|
||||
@ -314,11 +307,18 @@ class Dealer (Source):
|
||||
|
||||
# run the diff
|
||||
if self.playlist == diff.playlist and diff.date <= now:
|
||||
# FIXME: log
|
||||
self.on = True
|
||||
for source in self.controller.source:
|
||||
source.skip()
|
||||
|
||||
self.controller.log(
|
||||
source = self.id,
|
||||
diffusion = diff,
|
||||
date = now,
|
||||
comment = 'trigger the scheduled diffusion to liquidsoap; '
|
||||
'skip all other sources',
|
||||
)
|
||||
|
||||
|
||||
class Controller:
|
||||
connector = None
|
||||
@ -369,11 +369,13 @@ class Controller:
|
||||
return self.dealer
|
||||
return self.streams.get(source_id)
|
||||
|
||||
def next_diffusions (self, count = 5):
|
||||
def log (self, **kwargs):
|
||||
"""
|
||||
Return a list of the count next diffusions
|
||||
Create a log using **kwargs, and print info
|
||||
"""
|
||||
return models.Diffusion.get_next(self.station)[:count]
|
||||
log = models.Log(**kwargs)
|
||||
log.save()
|
||||
log.print()
|
||||
|
||||
def update_all (self):
|
||||
"""
|
||||
@ -384,6 +386,31 @@ class Controller:
|
||||
for source in self.streams.values():
|
||||
source.update()
|
||||
|
||||
def __change_log (self, source):
|
||||
last_log = models.Log.objects.filter(
|
||||
source = source.id,
|
||||
).prefetch_related('sound').order('-date')
|
||||
|
||||
on_air = source.current_sound
|
||||
if on_air == last_log.sound.path:
|
||||
return
|
||||
|
||||
self.log(
|
||||
source = source.id,
|
||||
sound = models.Sound.objects.get(path = on_air),
|
||||
start = tz.make_aware(tz.datetime.now()),
|
||||
comment = 'sound has changed'
|
||||
)
|
||||
|
||||
def monitor (self):
|
||||
"""
|
||||
Log changes in the sources, and call dealer.monitor.
|
||||
"""
|
||||
self.dealer.monitor()
|
||||
self.__change_log(self.dealer)
|
||||
for source in self.sources:
|
||||
self.__change_log(source)
|
||||
|
||||
|
||||
class Monitor:
|
||||
"""
|
||||
|
Reference in New Issue
Block a user