mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-10 10:03:38 -04:00
Merge pull request #1785 from alphagov/vb-report-tasks
Add import to reporting_tasks in scheduled tasks
This commit is contained in:
@@ -1,6 +1,3 @@
|
|||||||
from app import notify_celery
|
|
||||||
from notifications_utils.statsd_decorators import statsd
|
|
||||||
import random
|
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from app.models import (Notification,
|
from app.models import (Notification,
|
||||||
Rate,
|
Rate,
|
||||||
@@ -14,6 +11,8 @@ from app.models import (Notification,
|
|||||||
from app import db
|
from app import db
|
||||||
from sqlalchemy import func, desc, case
|
from sqlalchemy import func, desc, case
|
||||||
from app.dao.dao_utils import transactional
|
from app.dao.dao_utils import transactional
|
||||||
|
from notifications_utils.statsd_decorators import statsd
|
||||||
|
from app import notify_celery
|
||||||
|
|
||||||
|
|
||||||
def get_rate(non_letter_rates, letter_rates, notification_type, date, crown=None, rate_multiplier=None):
|
def get_rate(non_letter_rates, letter_rates, notification_type, date, crown=None, rate_multiplier=None):
|
||||||
@@ -26,10 +25,10 @@ def get_rate(non_letter_rates, letter_rates, notification_type, date, crown=None
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
@notify_celery.task(bind=True, name="create-nightly-billing", max_retries=15, default_retry_delay=300)
|
@notify_celery.task(name="create-nightly-billing")
|
||||||
@statsd(namespace="tasks")
|
@statsd(namespace="tasks")
|
||||||
@transactional
|
@transactional
|
||||||
def create_nightly_billing(self, day_start=None):
|
def create_nightly_billing(day_start=None):
|
||||||
if day_start is None:
|
if day_start is None:
|
||||||
day_start = datetime.date(datetime.utcnow()) - timedelta(days=3) # Nightly jobs consolidating last 3 days
|
day_start = datetime.date(datetime.utcnow()) - timedelta(days=3) # Nightly jobs consolidating last 3 days
|
||||||
# Task to be run after mid-night
|
# Task to be run after mid-night
|
||||||
@@ -44,14 +43,14 @@ def create_nightly_billing(self, day_start=None):
|
|||||||
Notification.template_id,
|
Notification.template_id,
|
||||||
Notification.service_id,
|
Notification.service_id,
|
||||||
Notification.notification_type,
|
Notification.notification_type,
|
||||||
|
func.coalesce(Notification.sent_by,
|
||||||
case(
|
case(
|
||||||
[
|
[
|
||||||
(Notification.notification_type == 'letter', func.coalesce(Notification.sent_by, 'dvla')),
|
(Notification.notification_type == 'letter', 'dvla'),
|
||||||
(Notification.notification_type == 'sms',
|
(Notification.notification_type == 'sms', 'unknown'),
|
||||||
func.coalesce(Notification.sent_by, random.choice(['mmg', 'firetext'])))
|
(Notification.notification_type == 'email', 'ses')
|
||||||
],
|
]),
|
||||||
else_='ses'
|
).label('sent_by'),
|
||||||
).label('sent_by'), # This could be null - this is a bug to be fixed.
|
|
||||||
func.coalesce(Notification.rate_multiplier, 1).label('rate_multiplier'),
|
func.coalesce(Notification.rate_multiplier, 1).label('rate_multiplier'),
|
||||||
func.coalesce(Notification.international, False).label('international'),
|
func.coalesce(Notification.international, False).label('international'),
|
||||||
func.sum(Notification.billable_units).label('billable_units'),
|
func.sum(Notification.billable_units).label('billable_units'),
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ class Config(object):
|
|||||||
CELERY_TIMEZONE = 'Europe/London'
|
CELERY_TIMEZONE = 'Europe/London'
|
||||||
CELERY_ACCEPT_CONTENT = ['json']
|
CELERY_ACCEPT_CONTENT = ['json']
|
||||||
CELERY_TASK_SERIALIZER = 'json'
|
CELERY_TASK_SERIALIZER = 'json'
|
||||||
CELERY_IMPORTS = ('app.celery.tasks', 'app.celery.scheduled_tasks')
|
CELERY_IMPORTS = ('app.celery.tasks', 'app.celery.scheduled_tasks', 'app.celery.reporting_tasks')
|
||||||
CELERYBEAT_SCHEDULE = {
|
CELERYBEAT_SCHEDULE = {
|
||||||
'run-scheduled-jobs': {
|
'run-scheduled-jobs': {
|
||||||
'task': 'run-scheduled-jobs',
|
'task': 'run-scheduled-jobs',
|
||||||
|
|||||||
@@ -261,7 +261,7 @@ def test_create_nightly_billing_null_sent_by_sms(
|
|||||||
assert record.rate == Decimal(1.33)
|
assert record.rate == Decimal(1.33)
|
||||||
assert record.billable_units == 1
|
assert record.billable_units == 1
|
||||||
assert record.rate_multiplier == 1
|
assert record.rate_multiplier == 1
|
||||||
assert record.provider in ['mmg', 'firetext']
|
assert record.provider == 'unknown'
|
||||||
|
|
||||||
|
|
||||||
@freeze_time('2018-01-15T03:30:00')
|
@freeze_time('2018-01-15T03:30:00')
|
||||||
|
|||||||
Reference in New Issue
Block a user