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 """epic-prod-past-import.py — clockwork past-campaign output ingest.
0003 
0004 The prod-ops agent's doer for the nightly ``catalog_sync`` chain step
0005 (also behind the Past tab's "Update from epic-prod" button flow and
0006 usable by hand): pull the cloned eic/epic-prod bookkeeping repo, then
0007 re-run the idempotent FULL/RECO past-campaign ingest so every campaign's
0008 recorded production content tracks what the production team publishes —
0009 no button required. The chain runs before the general 04:00 repo pull,
0010 so the pull here is what makes the ingest read today's upstream state.
0011 See ``docs/EPICPROD_DATA_LINEAGE.md`` and ``docs/PCS.md``.
0012 
0013 Usage::
0014 
0015     cd /data/wenauseic/github/swf-monitor/src
0016     source ../../swf-testbed/.venv/bin/activate && source ~/.env
0017     python ../scripts/epic-prod-past-import.py
0018 """
0019 import argparse
0020 import os
0021 import subprocess
0022 import sys
0023 
0024 THIS_DIR = os.path.dirname(os.path.abspath(__file__))
0025 sys.path.insert(0, os.path.join(THIS_DIR, '..', 'src'))
0026 os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'swf_monitor_project.settings')
0027 
0028 import django  # noqa: E402
0029 django.setup()
0030 
0031 from pcs.services import EPIC_PROD_PATH, import_epic_prod_past_campaigns  # noqa: E402
0032 
0033 
0034 def main():
0035     parser = argparse.ArgumentParser()
0036     parser.add_argument('--created-by', default='prodops_agent')
0037     parser.add_argument('--no-pull', action='store_true',
0038                         help='skip the git pull of the epic-prod clone')
0039     args = parser.parse_args()
0040 
0041     if not args.no_pull:
0042         pull = subprocess.run(
0043             ['git', '-C', EPIC_PROD_PATH, 'pull', '--ff-only'],
0044             capture_output=True, text=True, timeout=120)
0045         if pull.returncode != 0:
0046             # A failed pull is reported but not fatal: the ingest still
0047             # runs over the existing clone rather than silently skipping.
0048             print(f'WARNING: epic-prod pull failed '
0049                   f'(rc={pull.returncode}): {(pull.stderr or "").strip()}',
0050                   file=sys.stderr)
0051         else:
0052             print(f'epic-prod pull: {(pull.stdout or "").strip().splitlines()[-1]}')
0053 
0054     summary = import_epic_prod_past_campaigns(created_by=args.created_by)
0055     print(f"created={summary['created']} updated={summary['updated']} "
0056           f"errors={len(summary['errors'])}")
0057     for err in summary['errors']:
0058         print(f'ERROR: {err}', file=sys.stderr)
0059     return 1 if summary['errors'] else 0
0060 
0061 
0062 if __name__ == '__main__':
0063     sys.exit(main())