Add health reporting, container probe, and JNN channel support
Build and Publish TVJ EPG Image / build (push) Successful in 29s
Build and Publish TVJ EPG Image / build (push) Successful in 29s
This commit is contained in:
+35
-7
@@ -1,7 +1,8 @@
|
||||
"""Fetch each provider feed once and publish selected channels."""
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
import sys
|
||||
from epg.config import load
|
||||
from epg.health import record
|
||||
from epg.providers import PROVIDERS
|
||||
from epg.writers import atomic_write, m3u, xmltv
|
||||
|
||||
@@ -10,17 +11,44 @@ def run(environ=None):
|
||||
channels, xml_path, m3u_path = load(environ)
|
||||
feeds = {}
|
||||
schedules = {}
|
||||
report = {'checked_at': datetime.now(timezone.utc).isoformat(),
|
||||
'success': False, 'providers': {}, 'channels': {}}
|
||||
errors = []
|
||||
for channel in channels:
|
||||
provider = PROVIDERS[channel.provider]
|
||||
key = (channel.provider, channel.feed_url, channel.tenant)
|
||||
if key not in feeds:
|
||||
feeds[key] = provider.fetch(channel.feed_url, channel.tenant)
|
||||
schedules[channel.id] = provider.programmes(feeds[key], channel.channel_id)
|
||||
try:
|
||||
feeds[key] = provider.fetch(channel.feed_url, channel.tenant)
|
||||
report['providers'][channel.provider] = {'status': 'healthy'}
|
||||
except Exception as error:
|
||||
feeds[key] = error
|
||||
report['providers'][channel.provider] = {
|
||||
'status': 'unhealthy', 'error': type(error).__name__}
|
||||
try:
|
||||
if isinstance(feeds[key], Exception):
|
||||
raise feeds[key]
|
||||
schedules[channel.id] = provider.programmes(feeds[key], channel.channel_id)
|
||||
report['channels'][channel.id] = {'status': 'healthy'}
|
||||
except Exception as error:
|
||||
errors.append(error)
|
||||
report['channels'][channel.id] = {
|
||||
'status': 'unhealthy', 'error': type(error).__name__}
|
||||
if errors:
|
||||
record(xml_path, report)
|
||||
raise errors[0]
|
||||
# Fetch and render everything before replacing any previous output.
|
||||
xml_content = xmltv(channels, schedules)
|
||||
playlist = m3u(channels)
|
||||
atomic_write(xml_path, xml_content)
|
||||
atomic_write(m3u_path, playlist)
|
||||
try:
|
||||
xml_content = xmltv(channels, schedules)
|
||||
playlist = m3u(channels)
|
||||
atomic_write(xml_path, xml_content)
|
||||
atomic_write(m3u_path, playlist)
|
||||
report['success'] = True
|
||||
except Exception as error:
|
||||
report['output_error'] = type(error).__name__
|
||||
raise
|
||||
finally:
|
||||
record(xml_path, report)
|
||||
print(f"[{datetime.now().astimezone().isoformat()}] Wrote {xml_path} and {m3u_path}", flush=True)
|
||||
for channel in channels:
|
||||
programmes = schedules[channel.id]
|
||||
|
||||
Reference in New Issue
Block a user