from django.db.models.signals import post_delete, post_save
from django.dispatch import receiver
from assets.models import Asset
from common.decorators import on_transaction_commit
from common.signals import django_ready
from common.utils import get_logger
from ..utils import db_port_manager
logger = get_logger(__file__)
@receiver(django_ready)
def check_db_port_mapper(sender, **kwargs):
logger.info('Check oracle ports')
try:
db_port_manager.check()
except Exception as e:
pass
@receiver(post_save, sender=Asset)
@on_transaction_commit
def on_db_created(sender, instance: Asset, created, **kwargs):
if instance.type != 'oracle':
return
if not created:
logger.info("Oracle create signal recv: {} {}".format(instance, instance.type))
@receiver(post_delete, sender=Asset)
def on_db_delete(sender, instance, **kwargs):
logger.info("Oracle delete signal recv: {}".format(instance))