File indexing completed on 2026-06-26 08:40:22
0001
0002 """rucio-snapshot-update.py — refresh the JLab Rucio output snapshot for the
0003 current (+ last) PCS campaign and rematch produced datasets onto each task's
0004 ``overrides['outputs']``.
0005
0006 This is the prod-ops agent's doer for the catalog "Update from Rucio" button:
0007 the web view publishes ``rucio_snapshot_update`` to the agent, which runs this
0008 script in the background (off the WSGI request, which times out on the live
0009 JLab fetch) and pushes ``rucio_snapshot_ready`` to the browser when done.
0010 Django-bootstrap standalone script — also usable by hand or cron. See
0011 ``docs/EPICPROD_DATA_LINEAGE.md`` and ``docs/EPICPROD_OPS.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/rucio-snapshot-update.py
0018 """
0019 import os
0020 import sys
0021
0022 THIS_DIR = os.path.dirname(os.path.abspath(__file__))
0023 sys.path.insert(0, os.path.join(THIS_DIR, '..', 'src'))
0024 os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'swf_monitor_project.settings')
0025
0026 import django
0027 django.setup()
0028
0029 from pcs.services import refresh_rucio_snapshots
0030
0031
0032 def main(argv):
0033 result = refresh_rucio_snapshots(created_by='prodops_agent')
0034 for s in result['summaries']:
0035 paths = ', '.join(f'{k}={v}' for k, v in s.get('paths', {}).items())
0036 match = f" match={s['match']}" if s.get('match') else ''
0037 print(f" {s.get('campaign', '?')}: {paths}{match}")
0038 if result['errors']:
0039 for err in result['errors']:
0040 print(f'ERROR: {err}', file=sys.stderr)
0041 return 1
0042 return 0
0043
0044
0045 if __name__ == '__main__':
0046 sys.exit(main(sys.argv))