File indexing completed on 2026-08-12 09:36:13
0001
0002 """delivery-daily-rebuild.py — rebuild the campaign delivered-data
0003 daily record.
0004
0005 The prod-ops agent's doer for the nightly daily-record rebuild (a step
0006 of the ``catalog_sync`` chain): a full idempotent reconstruction of the
0007 per-ET-day, per-PC registered-basis delivery record from the JLab Rucio
0008 file inventory — the record the Snapper campaign view's curves draw
0009 from. Logic in ``swf_epicprod/analytics/delivery_daily.py``; see
0010 ``swf-epicprod/docs/CAMPAIGN_DELIVERY.md`` (Ongoing production).
0011 Django-bootstrap standalone script — also usable by hand.
0012
0013 Usage::
0014
0015 cd /data/wenauseic/github/swf-monitor/src
0016 source ../../swf-testbed/.venv/bin/activate && source ~/.env
0017 python ../scripts/delivery-daily-rebuild.py [--dry-run]
0018 """
0019 import argparse
0020 import json
0021 import os
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
0029 django.setup()
0030
0031 from swf_epicprod.analytics.delivery_daily import rebuild_delivery_daily
0032
0033
0034 def main():
0035 parser = argparse.ArgumentParser()
0036 parser.add_argument('--campaigns', default='',
0037 help='comma-separated campaign families '
0038 '(default: all in the catalog)')
0039 parser.add_argument('--dry-run', action='store_true',
0040 help='reconstruct and report without writing')
0041 parser.add_argument('--limit-files', type=int, default=0,
0042 help='cap the metadata pass for fast validation '
0043 '(implies --dry-run)')
0044 parser.add_argument('--created-by', default='prodops_agent')
0045 args = parser.parse_args()
0046 campaigns = tuple(c.strip() for c in args.campaigns.split(',')
0047 if c.strip()) or None
0048
0049 summary = rebuild_delivery_daily(
0050 campaigns, apply=not args.dry_run and not args.limit_files,
0051 created_by=args.created_by, limit_files=args.limit_files)
0052 print('SUMMARY ' + json.dumps(summary))
0053 return 0
0054
0055
0056 if __name__ == '__main__':
0057 sys.exit(main())