updated endpoint definitions/names and reformatted some files and code
This commit is contained in:
@@ -1,41 +1,51 @@
|
||||
import datetime
|
||||
import random
|
||||
|
||||
import connexion
|
||||
import peewee
|
||||
import six
|
||||
import asyncio
|
||||
|
||||
from swagger_server.models.job_response import JobResponse # noqa: E501
|
||||
from swagger_server import util
|
||||
from swagger_server.requets_db.models.vrsta import (Job, JobManager)
|
||||
from threading import Semaphore, Thread
|
||||
from swagger_server.requets_db.models.vrsta import (Job)
|
||||
from threading import Thread
|
||||
from swagger_server.classla import cl_utils
|
||||
|
||||
CLASSLA_CONCURANCE_LIMIT = 4
|
||||
classla_sem = asyncio.Semaphore(CLASSLA_CONCURANCE_LIMIT)
|
||||
|
||||
|
||||
def get_job_status(job_id, show_estimated_completion=None): # noqa: E501
|
||||
def delete_job(job_id): # noqa: E501
|
||||
"""Izbriše job
|
||||
|
||||
# noqa: E501
|
||||
|
||||
:param job_id:
|
||||
:type job_id: int
|
||||
|
||||
:rtype: str
|
||||
"""
|
||||
return 'Endpoint currently disabled'
|
||||
|
||||
|
||||
def get_job_status(job_id): # noqa: E501
|
||||
"""Vrne status
|
||||
|
||||
# noqa: E501
|
||||
|
||||
:param job_id:
|
||||
:type job_id: int
|
||||
:param show_estimated_completion: Calculate estimate time remaining based on various factors (could be inaccurate)
|
||||
:type show_estimated_completion: bool
|
||||
|
||||
:rtype: JobResponse
|
||||
"""
|
||||
try:
|
||||
job = Job.get_by_id(job_id)
|
||||
if not job.finished_on:
|
||||
est_com = None
|
||||
# todo: if estimate completion: calculate it and set it to est_com
|
||||
return JobResponse(finished_job=False, estimated_completion=est_com), 200
|
||||
return JobResponse(finished_job=True, completed_at=job.finished_on, job_result=job.job_output), 200
|
||||
except peewee.DoesNotExist as e:
|
||||
if job.started_on is None:
|
||||
return JobResponse(job_status="waiting in que", created_on=job.created_on), 200
|
||||
if job.started_on is not None and job.finished_on is None:
|
||||
return JobResponse(job_status="currently processing", created_on=job.created_on,
|
||||
started_on=job.started_on), 200
|
||||
if job.started_on is not None and job.finished_on is not None:
|
||||
return JobResponse(job_status="finished processing", created_on=job.created_on, started_on=job.started_on,
|
||||
finished_on=job.finished_on, job_result=job.job_output), 200
|
||||
except peewee.DoesNotExist:
|
||||
return "Job with this ID does not exist", 404
|
||||
|
||||
|
||||
@@ -43,6 +53,7 @@ def clear_up_unfinished_jobs():
|
||||
"""
|
||||
In case server crashed while jobs were in queue...
|
||||
"""
|
||||
# tu more but !=, ne deluje ce je "is not"
|
||||
Job.update(started_on=None).where(Job.started_on != None, Job.finished_on == None).execute()
|
||||
|
||||
|
||||
@@ -56,7 +67,7 @@ async def try_do_jobs():
|
||||
if classla_sem._value > 0:
|
||||
# classla
|
||||
unfinished_jobs = Job.select() \
|
||||
.where(Job.finished_on == None, Job.started_on == None, Job.job_type == 1) \
|
||||
.where(Job.finished_on == None, Job.started_on == None, Job.job_type == 2) \
|
||||
.limit(classla_sem._value)
|
||||
tasks = [
|
||||
asyncio.ensure_future(execute_classla_job(job))
|
||||
@@ -91,6 +102,8 @@ async def execute_classla_job(job: Job):
|
||||
|
||||
clear_up_unfinished_jobs()
|
||||
loop = asyncio.get_event_loop()
|
||||
|
||||
|
||||
def loop_in_thread(loop):
|
||||
asyncio.set_event_loop(loop)
|
||||
loop.run_until_complete(try_do_jobs())
|
||||
@@ -99,7 +112,6 @@ def loop_in_thread(loop):
|
||||
t = Thread(target=loop_in_thread, args=(loop,))
|
||||
t.start()
|
||||
|
||||
|
||||
# clear_up_unfinished_jobs()
|
||||
# loop = asyncio.get_event_loop()
|
||||
# loop.run_until_complete(try_do_jobs()) this version seems more at home, but it blocks the thread, fix that?
|
||||
|
||||
Reference in New Issue
Block a user