MCPcopy Create free account
hub / github.com/Dispatcharr/Dispatcharr / fetch_sd_mapped_guide_batch

Function fetch_sd_mapped_guide_batch

apps/epg/tasks.py:2573–2618  ·  view source on GitHub ↗

Fetch Schedules Direct guide data for all mapped stations on one source. Used when bulk EPG assignment would otherwise queue many per-EPG tasks.

(source_id, force=False, _defer_retry=0)

Source from the content-addressed store, hash-verified

2571
2572@shared_task(time_limit=3600, soft_time_limit=3500)
2573def fetch_sd_mapped_guide_batch(source_id, force=False, _defer_retry=0):
2574 """
2575 Fetch Schedules Direct guide data for all mapped stations on one source.
2576
2577 Used when bulk EPG assignment would otherwise queue many per-EPG tasks.
2578 """
2579 try:
2580 source = EPGSource.objects.get(id=source_id)
2581 except EPGSource.DoesNotExist:
2582 logger.error(f"EPGSource {source_id} not found for SD mapped guide batch")
2583 return
2584
2585 if source.source_type != 'schedules_direct':
2586 return "Not a Schedules Direct source"
2587
2588 if not acquire_task_lock('sd_mapped_guide_fetch', source_id):
2589 if _defer_retry < SD_MAPPED_GUIDE_FETCH_DEFER_MAX_RETRIES:
2590 logger.info(
2591 f"SD mapped guide batch for source {source_id} already in progress, "
2592 f"deferring retry {_defer_retry + 1}/"
2593 f"{SD_MAPPED_GUIDE_FETCH_DEFER_MAX_RETRIES}"
2594 )
2595 fetch_sd_mapped_guide_batch.apply_async(
2596 args=[source_id],
2597 kwargs={
2598 'force': force,
2599 '_defer_retry': _defer_retry + 1,
2600 },
2601 countdown=SD_MAPPED_GUIDE_BATCH_DEFER_SECONDS,
2602 )
2603 return "Deferred - batch already in progress"
2604 logger.warning(
2605 f"SD mapped guide batch for source {source_id} still locked after "
2606 f"{_defer_retry} deferrals; giving up"
2607 )
2608 return "Task already running"
2609
2610 lock_renewer = TaskLockRenewer('sd_mapped_guide_fetch', source_id)
2611 lock_renewer.start()
2612 try:
2613 logger.info(f"Fetching Schedules Direct guide for mapped stations (source: {source.name})")
2614 fetch_schedules_direct(source, mapped_guide_batch=True, force=force)
2615 return "SD mapped guide batch complete"
2616 finally:
2617 lock_renewer.stop()
2618 release_task_lock('sd_mapped_guide_fetch', source_id)
2619
2620
2621@shared_task(time_limit=3600, soft_time_limit=3500)

Calls 7

startMethod · 0.95
stopMethod · 0.95
acquire_task_lockFunction · 0.90
TaskLockRenewerClass · 0.90
release_task_lockFunction · 0.90
fetch_schedules_directFunction · 0.85
getMethod · 0.45