|
12 | 12 | register_task_handler, |
13 | 13 | ) |
14 | 14 |
|
| 15 | +from app_analytics.analytics_db_service import get_total_events_count |
15 | 16 | from app_analytics.influxdb_wrapper import get_current_api_usage |
16 | 17 | from integrations.flagsmith.client import get_client |
17 | 18 | from organisations import subscription_info_cache |
@@ -214,10 +215,18 @@ def charge_for_api_call_count_overages(): # type: ignore[no-untyped-def] |
214 | 215 | continue |
215 | 216 |
|
216 | 217 | subscription_cache = organisation.subscription_information_cache |
217 | | - api_usage = get_current_api_usage( |
218 | | - organisation_id=organisation.id, |
219 | | - date_start=subscription_cache.current_billing_term_starts_at, |
220 | | - ) |
| 218 | + if flags.is_feature_enabled( |
| 219 | + "get_current_api_usage_deprecated" |
| 220 | + ): # pragma: no cover |
| 221 | + api_usage = get_total_events_count( |
| 222 | + organisation, |
| 223 | + date_start=subscription_cache.current_billing_term_starts_at, |
| 224 | + ) |
| 225 | + else: |
| 226 | + api_usage = get_current_api_usage( |
| 227 | + organisation_id=organisation.id, |
| 228 | + date_start=subscription_cache.current_billing_term_starts_at, |
| 229 | + ) |
221 | 230 |
|
222 | 231 | # Grace period for organisations < 200% of usage. |
223 | 232 | if ( |
@@ -347,10 +356,18 @@ def restrict_use_due_to_api_limit_grace_period_over() -> None: |
347 | 356 | OrganisationBreachedGracePeriod.objects.get_or_create(organisation=organisation) |
348 | 357 |
|
349 | 358 | subscription_cache = organisation.subscription_information_cache |
350 | | - api_usage = get_current_api_usage( |
351 | | - organisation_id=organisation.id, |
352 | | - date_start=now - timedelta(days=30), |
353 | | - ) |
| 359 | + if flags.is_feature_enabled( |
| 360 | + "get_current_api_usage_deprecated" |
| 361 | + ): # pragma: no cover |
| 362 | + api_usage = get_total_events_count( |
| 363 | + organisation, |
| 364 | + date_start=now - timedelta(days=30), |
| 365 | + ) |
| 366 | + else: |
| 367 | + api_usage = get_current_api_usage( |
| 368 | + organisation_id=organisation.id, |
| 369 | + date_start=now - timedelta(days=30), |
| 370 | + ) |
354 | 371 | if api_usage / subscription_cache.allowed_30d_api_calls < 1.0: |
355 | 372 | logger.info( |
356 | 373 | f"API use for organisation {organisation.id} has fallen to below limit, so not restricting use." |
|
0 commit comments