from celery.schedules import crontab
from celery.task import periodic_task
from django.conf import settings
from django.db.models import Count

from corehq.util.datadog.gauges import datadog_gauge
from pillow_retry.models import PillowError


@periodic_task(
    run_every=crontab(minute="*/15"),
    queue=settings.CELERY_PERIODIC_QUEUE,
)
def record_pillow_error_queue_size():
    data = PillowError.objects.values('pillow').annotate(num_errors=Count('id'))
    for row in data:
        datadog_gauge('commcare.pillowtop.error_queue', row['num_errors'], tags=[
            'pillow_name:%s' % row['pillow'],
            'host:celery',
            'group:celery'
        ])

from celery.schedules import crontab
from celery.task import periodic_task
from django.conf import settings
from django.db.models import Count

from corehq.util.datadog.gauges import datadog_gauge
from pillow_retry.models import PillowError


@periodic_task(
    run_every=crontab(minute="*/15"),
    queue=settings.CELERY_PERIODIC_QUEUE,
)
def record_pillow_error_queue_size():
    data = PillowError.objects.values('pillow').annotate(num_errors=Count('id'))
    for row in data:
        datadog_gauge('commcare.pillowtop.error_queue', row['num_errors'], tags=[
            'pillow_name:%s' % row['pillow'],
            'host:celery',
            'group:celery',
            'error_type:%s' % row['error_type']
        ])

Send error-type info to pillow error DD metrics
Send error-type info to pillow error DD metrics
