@@ -0,0 +1,1301 @@
+from celery import task%0Afrom celery.exceptions import SoftTimeLimitExceeded%0Afrom go_http import HttpApiSender%0Aimport control.settings as settings%0Afrom django.db import connection%0Aimport logging%0Alogger = logging.getLogger(__name__)%0A%0A%0A@task()%0Adef ensure_one_servicerating():%0A    %22%22%22 %0A    Fixes issues caused by upstream failures that lead%0A    to users having multiple recorded serviceratings%0A    Runs daily%0A    %22%22%22%0A    cursor = connection.cursor()%0A    cursor.execute(%22DELETE FROM servicerating_response WHERE contact_id NOT IN %5C%0A    (SELECT MAX(id) as id FROM servicerating_contact GROUP BY key)%22)%0A    affected = cursor.rowcount%0A    vumi_fire_metric.delay(metric=%22servicerating.duplicates%22, value=affected, agg=%22last%22)%0A    return affected%0A%0A%0A@task()%0Adef vumi_fire_metric(metric, value, agg, sender=None):%0A    try:%0A        if sender is None: %0A            sender = HttpApiSender(%0A                account_key=settings.VUMI_GO_ACCOUNT_KEY,%0A                conversation_key=settings.VUMI_GO_CONVERSATION_KEY,%0A                conversation_token=settings.VUMI_GO_ACCOUNT_TOKEN%0A            )%0A        sender.fire_metric(metric, value, agg=agg)%0A        return sender%0A    except SoftTimeLimitExceeded:%0A        logger.error('Soft time limit exceed processing metric fire to Vumi HTTP API via Celery', exc_info=True)%0A

add tasks