diff --git a/photoapp/api.py b/photoapp/api.py index 56c7b92..f723116 100644 --- a/photoapp/api.py +++ b/photoapp/api.py @@ -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" diff --git a/photoapp/jobs.py b/photoapp/jobs.py new file mode 100644 index 0000000..ab69fe2 --- /dev/null +++ b/photoapp/jobs.py @@ -0,0 +1,4 @@ + +class JobsDAO(object): + + pass \ No newline at end of file diff --git a/photoapp/types.py b/photoapp/types.py index dea32e7..293776b 100644 --- a/photoapp/types.py +++ b/photoapp/types.py @@ -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"}}