misc jobs progress

This commit is contained in:
dave 2023-01-12 22:58:33 -08:00
parent 44f7966152
commit 7b487e562b
3 changed files with 93 additions and 0 deletions

View File

@ -38,6 +38,7 @@ class PhotosApiV1(object):
self.stats = PhotosApiV1Stats()
self.photos = PhotosApiV1Photos()
self.tags = PhotosApiV1PhotoTags()
self.jobs = JobsApiV1(library)
def GET(self):
cherrypy.response.headers["Content-type"] = "text/plain"
@ -284,3 +285,46 @@ class PhotosApiV1PhotoTags(object):
slug=slugify(tagname)))
db.commit()
return {}
@cherrypy.popargs("uuid")
class JobsApiV1(object):
def __init__(self, library):
self.library = library
@cherrypy.expose
@cherrypy.tools.allow(methods=["POST", "GET"])
@cherrypy.tools.json_out()
def index(
self,
uuid=None, # when fetching an existing job, the job's UUID
):
"""
show the list of jobs or the specified job
or, if we're POST/PUTing, create a new job
POSTing without the job_args field will tell you the list of job args you need to submit
POSTing with job_args will actually create the job
"""
# if cherrypy.request.method == "POST": # creating job
# print()
# print('body', cherrypy.request.body.read())
# return 'handle post'
# return 'job: ' + str(uuid)
# return cherrypy.dispatch.Dispatcher.call(self.other)
request, response = cherrypy.request, cherrypy.response
request.dispatch = cherrypy.dispatch.Dispatcher()
cherrypy._cptools.HandlerTool.callable_method_handler(self.other)
print("response:", response)
return "lol"
@cherrypy.expose
def other(self):
print("in other")
yield "other result"

4
photoapp/jobs.py Normal file
View File

@ -0,0 +1,4 @@
class JobsDAO(object):
pass

View File

@ -220,3 +220,48 @@ class User(Base):
def to_json(self):
return dict(name=self.name, status=self.status.name)
class JobStatus(enum.Enum):
paused = 0
ready = 1
running = 2
done = 3
error = 4
class Job(Base):
__tablename__ = 'jobs'
id = Column(Integer, primary_key=True)
uuid = Column(Unicode(length=36), unique=True, nullable=False, default=lambda: str(uuid.uuid4()))
created = Column(DateTime, nullable=False, default=lambda: datetime.now())
job_name = Column(String(length=64), nullable=False)
status = Column(Enum(JobStatus), nullable=False, default=JobStatus.paused)
targets = relationship("JobTarget", back_populates="job")
def to_json(self):
return {attr: getattr(self, attr) for attr in
{"uuid", "created", "job_name", "status"}}
class JobTargetType(enum.Enum):
photo = 0
photoset = 1
tag = 2
class JobTarget(Base):
__tablename__ = 'job_targets'
id = Column(Integer, primary_key=True)
job_id = Column(Integer, ForeignKey("jobs.id"), nullable=False)
job = relationship("Job", back_populates="targets", foreign_keys=[job_id])
target_type = Column(Enum(JobTargetType), nullable=False)
target = Column(Integer, nullable=False)
def to_json(self):
return {attr: getattr(self, attr) for attr in
{"target_type", "target"}}