import logging

from django.db import transaction
from django.db.models.signals import post_save
from django.dispatch import receiver
from incident.models import Incident

from incident_export.tasks import export_incident

_log = logging.getLogger(__name__)


@receiver(post_save, sender=Incident)
def post_save_incident_export(sender, **kwargs):
    incident = kwargs.get('instance')
    transaction.on_commit(lambda: export_incident.apply_async(args=(incident.pk,), ))
