billing: Add cron job to run invoice_plans once a day.

Fixes #11960
This commit is contained in:
Vishnu Ks 2019-04-26 16:45:11 +05:30 committed by Tim Abbott
parent f46b5a8ba1
commit ecdd3bea43
4 changed files with 38 additions and 0 deletions

View File

@ -0,0 +1,5 @@
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
USER=zulip
0 22 * * * zulip /home/zulip/deployments/current/manage.py invoice_plans

View File

@ -38,6 +38,16 @@ class zulip_ops::prod_app_frontend {
mode => '0644',
source => 'puppet:///modules/zulip/cron.d/calculate-first-visible-message-id',
}
# TODO: This should ideally move to a prod_app_frontend_once.pp
file { '/etc/cron.d/invoice-plans':
ensure => file,
owner => 'root',
group => 'root',
mode => '0644',
source => 'puppet:///modules/zulip/cron.d/invoice-plans',
}
# Prod has our Apple Push Notifications Service private key at
# /etc/ssl/django-private/apns-dist.pem
}

View File

@ -389,3 +389,12 @@ class TestConvertMattermostData(ZulipTestCase):
mattermost_data_dir=os.path.realpath(mm_fixtures),
output_dir=os.path.realpath(output_dir),
)
class TestInvoicePlans(ZulipTestCase):
COMMAND_NAME = 'invoice_plans'
def test_if_command_calls_invoice_plans_as_needed(self) -> None:
with patch('zilencer.management.commands.invoice_plans.invoice_plans_as_needed') as m:
call_command(self.COMMAND_NAME)
m.assert_called_once()

View File

@ -0,0 +1,14 @@
from typing import Any
from django.conf import settings
from zerver.lib.management import ZulipBaseCommand
if settings.BILLING_ENABLED:
from corporate.lib.stripe import invoice_plans_as_needed
class Command(ZulipBaseCommand):
help = """Generates invoices for customers if needed."""
def handle(self, *args: Any, **options: Any) -> None:
if settings.BILLING_ENABLED:
invoice_plans_as_needed()