tasks.py 815 Bytes
from __future__ import absolute_import

from celery.task import Task
from analyzer.tasks import analysis
from pyrosapp.models import *

import time
import os

IMAGES_FOLDER = 'simulation_images'

class execute_plan(Task):

    def run(self, plan_pk):
#         print("ex plan : ", self.request.id)
        TaskId.objects.filter(task_id=self.request.id).delete()
        message = 'Start plan ' + str(plan_pk) + ' execution'
        Log.objects.create(agent='Observation manager', message=message)
        print("execute_plan : ", plan_pk)
        time.sleep(1)
        with open(os.path.join(IMAGES_FOLDER, str(plan_pk)), 'w'):
            pass
        analysis.delay(plan_pk)
        message = 'Finished plan ' + str(plan_pk) + ' execution'
        Log.objects.create(agent='Observation manager', message=message)