def maintenance_post_save(sender, **kwargs): """ maintenance post save signal. Creates the maintenance task on celery and its HostMaintenance objetcs. """ maintenance = kwargs.get("instance") is_new = kwargs.get("created") LOG.debug("maintenance post-save triggered") if is_new or not maintenance.celery_task_id: LOG.info("Spawning task and HostMaintenance objects...") if maintenance.save_host_maintenance(): if maintenance.scheduled_for > datetime.now(): task = execute_scheduled_maintenance.apply_async( args=[maintenance.id], eta=maintenance.scheduled_for.replace( tzinfo=tz.tzlocal() ).astimezone(tz.tzutc()) ) else: task = execute_scheduled_maintenance.apply_async( args=[maintenance.id], countdown=5 ) maintenance.celery_task_id = task.task_id maintenance.save()