Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-09 10:47:23

0001 #!/usr/bin/env python3
0002 """nersc-allocation-read.py — read the NERSC allocation balance of the
0003 projects production charges, from the NERSC IRI API with the access
0004 token file a PanDA operations cron refreshes daily (swf-epicprod
0005 docs/CONTINUOUS_PRODUCTION.md, Placement, Closed queues; logic in
0006 swf_epicprod/nersc_allocation.py).
0007 
0008 The prod-ops agent's doer for ``nersc_allocation_read``, hourly by cron
0009 enqueue. Stores the cached product ``nersc_allocation`` and records one
0010 ``nersc_allocation_read`` action. Django-bootstrap standalone script,
0011 also usable by hand::
0012 
0013     cd /data/wenauseic/github/swf-monitor/src
0014     source ../../swf-testbed/.venv/bin/activate && source ~/.env
0015     python ../scripts/nersc-allocation-read.py [--created-by NAME]
0016 
0017 Prints the balance lines and one ``SUMMARY`` JSON line; exit 1 when the
0018 balance could not be read.
0019 """
0020 import argparse
0021 import json
0022 import os
0023 import sys
0024 
0025 THIS_DIR = os.path.dirname(os.path.abspath(__file__))
0026 sys.path.insert(0, os.path.join(THIS_DIR, '..', 'src'))
0027 os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'swf_monitor_project.settings')
0028 
0029 import django  # noqa: E402
0030 django.setup()
0031 
0032 from swf_epicprod.nersc_allocation import line, run  # noqa: E402
0033 
0034 
0035 def main():
0036     ap = argparse.ArgumentParser(description=__doc__.split('\n\n')[0])
0037     ap.add_argument('--created-by', default='nersc_allocation',
0038                     help='who runs the read (the record carries it)')
0039     args = ap.parse_args()
0040     record = run(created_by=args.created_by)
0041     for text in line(record):
0042         print(text)
0043     print('SUMMARY ' + json.dumps({k: v for k, v in record.items() if k != 'token_file'},
0044                                   default=str))
0045     return 1 if record.get('error') else 0
0046 
0047 
0048 if __name__ == '__main__':
0049     sys.exit(main())