|
14 | 14 | from coldfront.core.allocation.models import Allocation, AllocationStatusChoice
|
15 | 15 | import pytz
|
16 | 16 |
|
17 |
| -from nerc_rates import load_from_url |
18 | 17 |
|
19 | 18 | logging.basicConfig(level=logging.INFO)
|
20 | 19 | logger = logging.getLogger(__name__)
|
21 | 20 |
|
| 21 | +_RATES = None |
| 22 | + |
| 23 | + |
| 24 | +def get_rates(): |
| 25 | + # nerc-rates doesn't work with Python 3.9, which is what ColdFront is currently |
| 26 | + # using in Production. Lazily load the rates only when either of the storage rates |
| 27 | + # is not set via CLI arguments, so we can keep providing them via CLI until we upgrade |
| 28 | + # Python version. |
| 29 | + global _RATES |
| 30 | + |
| 31 | + if _RATES is None: |
| 32 | + from nerc_rates import load_from_url |
| 33 | + _RATES = load_from_url() |
| 34 | + return _RATES |
| 35 | + |
22 | 36 |
|
23 | 37 | @dataclasses.dataclass
|
24 | 38 | class InvoiceRow:
|
@@ -200,20 +214,18 @@ def process_invoice_row(allocation, attrs, su_name, rate):
|
200 | 214 | resources__in=openshift_resources
|
201 | 215 | )
|
202 | 216 |
|
203 |
| - rates = load_from_url() |
204 |
| - |
205 | 217 | if options['openstack_gb_rate']:
|
206 | 218 | openstack_storage_rate = options['openstack_gb_rate']
|
207 | 219 | else:
|
208 | 220 | openstack_storage_rate = Decimal(
|
209 |
| - rates.get_value_at('Storage GB Rate', options["invoice_month"]) |
| 221 | + get_rates().get_value_at('Storage GB Rate', options["invoice_month"]) |
210 | 222 | )
|
211 | 223 |
|
212 | 224 | if options['openshift_gb_rate']:
|
213 | 225 | openshift_storage_rate = options['openshift_gb_rate']
|
214 | 226 | else:
|
215 | 227 | openshift_storage_rate = Decimal(
|
216 |
| - rates.get_value_at('Storage GB Rate', options["invoice_month"]) |
| 228 | + get_rates().get_value_at('Storage GB Rate', options["invoice_month"]) |
217 | 229 | )
|
218 | 230 |
|
219 | 231 | logger.info(f'Using storage rate {openstack_storage_rate} (Openstack) and '
|
|
0 commit comments