local_tasks.py 975 Bytes
Newer Older
1
from manager.mancelery import celery
Guba Sándor committed
2

3 4

@celery.task
5
def async_instance_operation(operation_id, instance_pk, activity_pk, **kwargs):
6 7 8 9 10 11
    from vm.models import Instance, InstanceActivity
    instance = Instance.objects.get(pk=instance_pk)
    operation = getattr(instance, operation_id)
    activity = InstanceActivity.objects.get(pk=activity_pk)

    # save async task UUID to activity
12
    activity.task_uuid = async_instance_operation.request.id
13 14 15
    activity.save()

    return operation._exec_op(activity=activity, **kwargs)
16 17 18


@celery.task
19 20 21 22 23 24 25 26 27 28 29
def async_node_operation(operation_id, node_pk, activity_pk, **kwargs):
    from vm.models import Node, NodeActivity
    node = Node.objects.get(pk=node_pk)
    operation = getattr(node, operation_id)
    activity = NodeActivity.objects.get(pk=activity_pk)

    # save async task UUID to activity
    activity.task_uuid = async_node_operation.request.id
    activity.save()

    return operation._exec_op(activity=activity, **kwargs)