# -*- coding: utf-8 -*-
from django.utils import timezone

from celery import Task
from celery.utils.log import get_task_logger

logger = get_task_logger(__name__)


class PurgeUnpublishedExportsTask(Task):
    """
    Purge unpublished export tasks after 48 hours.
    """

    name = "Purge Unpublished Exports"

    def run(self,):
        from eventkit_cloud.jobs.models import Job
        time_limit = timezone.now() - timezone.timedelta(hours=48)
        expired_jobs = Job.objects.filter(created_at__lt=time_limit, published=False)
        count = expired_jobs.count()
        logger.debug('Purging {0} unpublished exports.'.format(count))
        expired_jobs.delete()


# -*- coding: utf-8 -*-
from django.utils import timezone

from celery import Task
from celery.utils.log import get_task_logger
from celery.app.registry import TaskRegistry

logger = get_task_logger(__name__)


class PurgeUnpublishedExportsTask(Task):
    """
    Purge unpublished export tasks after 48 hours.
    """

    name = "Purge Unpublished Exports"

    def run(self,):
        from eventkit_cloud.jobs.models import Job
        time_limit = timezone.now() - timezone.timedelta(hours=48)
        expired_jobs = Job.objects.filter(created_at__lt=time_limit, published=False)
        count = expired_jobs.count()
        logger.debug('Purging {0} unpublished exports.'.format(count))
        expired_jobs.delete()

TaskRegistry().register(PurgeUnpublishedExportsTask())

Install celery beat, register tasks (untested)
Install celery beat, register tasks (untested)
