| 590 | |
| 591 | @shared_task(time_limit=14400) |
| 592 | def refresh_epg_data(source_id, force=False): |
| 593 | if not acquire_task_lock('refresh_epg_data', source_id): |
| 594 | logger.debug(f"EPG refresh for {source_id} already running") |
| 595 | return |
| 596 | |
| 597 | lock_renewer = TaskLockRenewer('refresh_epg_data', source_id) |
| 598 | lock_renewer.start() |
| 599 | |
| 600 | _release_task_db_connection() |
| 601 | |
| 602 | try: |
| 603 | return _refresh_epg_data_impl(source_id, force=force) |
| 604 | except Exception as e: |
| 605 | logger.error( |
| 606 | f"Error in refresh_epg_data for source {source_id}: {e}", |
| 607 | exc_info=True, |
| 608 | ) |
| 609 | _set_epg_source_status( |
| 610 | source_id, |
| 611 | EPGSource.STATUS_ERROR, |
| 612 | f"Error refreshing EPG data: {str(e)[:500]}", |
| 613 | notify_error=True, |
| 614 | ws_error=str(e)[:500], |
| 615 | ) |
| 616 | finally: |
| 617 | _ensure_epg_refresh_terminal_status(source_id) |
| 618 | _release_task_db_connection() |
| 619 | gc.collect() |
| 620 | lock_renewer.stop() |
| 621 | release_task_lock('refresh_epg_data', source_id) |
| 622 | |
| 623 | |
| 624 | def _refresh_epg_data_impl(source_id, force=False): |