2022-10-19 09:05:21 +00:00
|
|
|
from celery import shared_task
|
|
|
|
|
|
|
|
from orgs.utils import tmp_to_root_org, tmp_to_org
|
|
|
|
from common.utils import get_logger, get_object_or_none
|
|
|
|
|
|
|
|
logger = get_logger(__file__)
|
|
|
|
|
|
|
|
|
2022-11-02 09:27:47 +00:00
|
|
|
@shared_task(queue='ansible')
|
2022-10-25 10:43:34 +00:00
|
|
|
def execute_automation(pid, trigger, mode):
|
2022-10-19 09:05:21 +00:00
|
|
|
with tmp_to_root_org():
|
2022-10-25 10:43:34 +00:00
|
|
|
instance = get_object_or_none(mode, pk=pid)
|
2022-10-19 09:05:21 +00:00
|
|
|
if not instance:
|
2022-10-25 10:43:34 +00:00
|
|
|
logger.error("No automation task found: {}".format(pid))
|
2022-10-19 09:05:21 +00:00
|
|
|
return
|
|
|
|
with tmp_to_org(instance.org):
|
|
|
|
instance.execute(trigger)
|