Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-21 08:46:24

0001 #!/usr/bin/env python3
0002 """Refresh current campaign progress data and rendered table cache."""
0003 import argparse
0004 import os
0005 import sys
0006 from pathlib import Path
0007 
0008 
0009 ROOT = Path(__file__).resolve().parents[1]
0010 SRC = ROOT / "src"
0011 sys.path.insert(0, str(SRC))
0012 os.environ.setdefault("DJANGO_SETTINGS_MODULE", "swf_monitor_project.settings")
0013 
0014 import django  # noqa: E402
0015 
0016 django.setup()
0017 
0018 # Provenance probe: a warning in this doer's output cited a dev-venv Django
0019 # path that no direct probe of the deployed venv reproduces; report where
0020 # this subprocess actually runs from (2026-07-12).
0021 print(f"interpreter={sys.executable} django={django.__file__}", file=sys.stderr)
0022 
0023 from pcs.models import Campaign  # noqa: E402
0024 from pcs.services import (  # noqa: E402
0025     load_campaign_progress_snapshot,
0026     refresh_campaign_progress_snapshot,
0027 )
0028 from pcs.views import rebuild_current_task_list_html_cache  # noqa: E402
0029 from swf_epicprod.analytics.rollup import campaign_status  # noqa: E402
0030 
0031 
0032 def main():
0033     parser = argparse.ArgumentParser()
0034     parser.add_argument("--generated-by", default="progress_refresh")
0035     args = parser.parse_args()
0036 
0037     from pcs.views import _campaigns_with_inflow
0038 
0039     # Producing campaigns are the assessment targets and lead the set;
0040     # usually identical to current, distinct around lifecycle transitions.
0041     targets = [camp for camp, _ in _campaigns_with_inflow()]
0042     current = Campaign.objects.filter(lifecycle="current").order_by("name").first()
0043     if current is not None and all(c.pk != current.pk for c in targets):
0044         targets.append(current)
0045     if not targets:
0046         print("No producing or current campaign defined.", file=sys.stderr)
0047         return 2
0048 
0049     for campaign in targets:
0050         progress = refresh_campaign_progress_snapshot(
0051             campaign, generated_by=args.generated_by)
0052         snapshot = load_campaign_progress_snapshot(campaign) or {}
0053         table = rebuild_current_task_list_html_cache(
0054             campaign, "progress", progress_snapshot=snapshot)
0055         # The catalog view has no other clockwork rebuilder — without this it
0056         # serves its stale copy indefinitely (page-load rebuild is suppressed).
0057         catalog_table = rebuild_current_task_list_html_cache(campaign, "catalog")
0058         analytics = campaign_status(
0059             campaign.name, window_days=1, record=True,
0060             generated_by=args.generated_by)
0061         print(
0062             "campaign={campaign} tasks={tasks} warnings={warnings} "
0063             "table_bytes={table_bytes} catalog_table_bytes={catalog_bytes} "
0064             "generated_at={generated_at} analytics_at={analytics_at}".format(
0065                 campaign=progress["campaign"],
0066                 tasks=progress["tasks"],
0067                 warnings=len(progress["errors"]),
0068                 table_bytes=table["html_bytes"],
0069                 catalog_bytes=catalog_table["html_bytes"],
0070                 generated_at=progress["generated_at"],
0071                 analytics_at=analytics["generated_at"],
0072             )
0073         )
0074     return 0
0075 
0076 
0077 if __name__ == "__main__":
0078     raise SystemExit(main())