diff --git a/server/celery-queue/tasks.py b/server/celery-queue/tasks.py index 6d68ed8..20bad7a 100644 --- a/server/celery-queue/tasks.py +++ b/server/celery-queue/tasks.py @@ -30,7 +30,7 @@ def track_celery(method): """ This decorator measures celery task meta data and store it in Mysql db. - + Usage: Decorate your functions like this: @track_celery @@ -56,7 +56,7 @@ def download_file( url: str, dst: str): r = requests.get(url) with open(dst, 'wb') as f: f.write(r.content) - + def retrieve_output_file(target_file:dict, folder): file_pattern=os.path.join(folder, target_file["files"]) file_list=glob.glob(file_pattern) @@ -91,7 +91,7 @@ def write_to_temp_file(name:str, data:str, folder:str): # problem_file = f'{tmpfolder}/{os.path.basename(problem_url)}' # download_file(problem_url, problem_file) - + # # Will generate a single output file (the plan) which is returned via HTTP # command = f"{solver} {domain_file} {problem_file}" # res = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, @@ -101,20 +101,20 @@ def write_to_temp_file(name:str, data:str, folder:str): # # remove the tmp/fies once we finish # os.remove(domain_file) # os.remove(problem_file) - + # plan = retrieve_output_file(PACKAGES[solver]['endpoint']['services']['solve']['return']['file'], tmpfolder) - + # shutil.rmtree(tmpfolder) # return {'stdout': res.stdout, 'stderr': res.stderr, 'plan':plan} # Running generic planutils packages with no solver-specific assumptions -@celery.task(name='tasks.run.package',soft_time_limit=TIME_LIMIT,bind=True) +@celery.task(name='tasks.run.package',soft_time_limit=TIME_LIMIT+10,bind=True) @track_celery def run_package(self, package: str, arguments:dict, call:str, output_file:dict,**kwargs): - + try: tmpfolder = tempfile.mkdtemp() # Write files and replace args in the call string @@ -125,10 +125,11 @@ def run_package(self, package: str, arguments:dict, call:str, output_file:dict,* # k is a file, we want to replace with the file path call = call.replace("{%s}" % k, k) else: - # k needs to be replaced with the value + # k needs to be replaced with the value call = call.replace("{%s}" % k, str(v['value'])) - # Run the command + # add the timeout to the call + call = f"timeout {TIME_LIMIT} planutils run {call}" res = subprocess.run(call, stdout=subprocess.PIPE, stderr=subprocess.PIPE, executable='/bin/bash', encoding='utf-8', shell=True, cwd=tmpfolder) @@ -139,4 +140,4 @@ def run_package(self, package: str, arguments:dict, call:str, output_file:dict,* result={"stdout":res.stdout, "stderr":res.stderr, "call":call, "output":output,"output_type":output_file["type"]} return result,arguments except SoftTimeLimitExceeded as e: - return {"stdout":"Request Time Out", "stderr":"", "call":call, "output":{},"output_type":output_file["type"]},arguments \ No newline at end of file + return {"stdout":"Request Time Out", "stderr":"", "call":call, "output":{},"output_type":output_file["type"]},arguments