From 33251c191c126a977feae983b4db674782f2661a Mon Sep 17 00:00:00 2001 From: Zach Aysan Date: Fri, 3 May 2024 14:59:15 +0000 Subject: [PATCH] Run the task more frequently --- api/organisations/tasks.py | 5 +++-- .../unit/organisations/test_unit_organisations_tasks.py | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/api/organisations/tasks.py b/api/organisations/tasks.py index b4223fae7a67..a49557231ec8 100644 --- a/api/organisations/tasks.py +++ b/api/organisations/tasks.py @@ -217,7 +217,7 @@ def charge_for_api_call_count_overages(): # Only apply charges to ongoing subscriptions that are close to # being charged due to being at the end of the billing term. - closing_billing_term = now + timedelta(hours=12) + closing_billing_term = now + timedelta(hours=1) organisation_ids = set( OrganisationAPIUsageNotification.objects.filter( @@ -284,6 +284,7 @@ def charge_for_api_call_count_overages(): register_recurring_task( run_every=timedelta(hours=12), )(handle_api_usage_notifications) + register_recurring_task( - run_every=timedelta(hours=12), + run_every=timedelta(minutes=30), )(charge_for_api_call_count_overages) diff --git a/api/tests/unit/organisations/test_unit_organisations_tasks.py b/api/tests/unit/organisations/test_unit_organisations_tasks.py index e28eab4f0761..4549eb709e74 100644 --- a/api/tests/unit/organisations/test_unit_organisations_tasks.py +++ b/api/tests/unit/organisations/test_unit_organisations_tasks.py @@ -470,7 +470,7 @@ def test_charge_for_api_call_count_overages_scale_up( allowed_30d_api_calls=10_000, chargebee_email="test@example.com", current_billing_term_starts_at=now - timedelta(days=30), - current_billing_term_ends_at=now + timedelta(hours=6), + current_billing_term_ends_at=now + timedelta(minutes=30), ) organisation.subscription.subscription_id = "fancy_sub_id23" organisation.subscription.plan = "scale-up-v2" @@ -532,7 +532,7 @@ def test_charge_for_api_call_count_overages_start_up( allowed_30d_api_calls=10_000, chargebee_email="test@example.com", current_billing_term_starts_at=now - timedelta(days=30), - current_billing_term_ends_at=now + timedelta(hours=6), + current_billing_term_ends_at=now + timedelta(minutes=30), ) organisation.subscription.subscription_id = "fancy_sub_id23" organisation.subscription.plan = "startup-v2"