選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

task_service.py 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #
  2. # Copyright 2024 The InfiniFlow Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. from peewee import Expression
  17. from api.db.db_models import DB
  18. from api.db import StatusEnum, FileType, TaskStatus
  19. from api.db.db_models import Task, Document, Knowledgebase, Tenant
  20. from api.db.services.common_service import CommonService
  21. from api.db.services.document_service import DocumentService
  22. class TaskService(CommonService):
  23. model = Task
  24. @classmethod
  25. @DB.connection_context()
  26. def get_tasks(cls, tm, mod=0, comm=1, items_per_page=64):
  27. fields = [cls.model.id, cls.model.doc_id, cls.model.from_page,cls.model.to_page, Document.kb_id, Document.parser_id, Document.name, Document.type, Document.location, Document.size, Knowledgebase.tenant_id, Tenant.embd_id, Tenant.img2txt_id, Tenant.asr_id, cls.model.update_time]
  28. docs = cls.model.select(*fields) \
  29. .join(Document, on=(cls.model.doc_id == Document.id)) \
  30. .join(Knowledgebase, on=(Document.kb_id == Knowledgebase.id)) \
  31. .join(Tenant, on=(Knowledgebase.tenant_id == Tenant.id))\
  32. .where(
  33. Document.status == StatusEnum.VALID.value,
  34. ~(Document.type == FileType.VIRTUAL.value),
  35. cls.model.progress == 0,
  36. cls.model.update_time >= tm,
  37. (Expression(cls.model.create_time, "%%", comm) == mod))\
  38. .order_by(cls.model.update_time.asc())\
  39. .paginate(1, items_per_page)
  40. return list(docs.dicts())
  41. @classmethod
  42. @DB.connection_context()
  43. def do_cancel(cls, id):
  44. try:
  45. task = cls.model.get_by_id(id)
  46. _, doc = DocumentService.get_by_id(task.doc_id)
  47. return doc.run == TaskStatus.CANCEL.value
  48. except Exception as e:
  49. pass
  50. return True