Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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
  19. from api.db.db_models import Task, Document, Knowledgebase, Tenant
  20. from api.db.services.common_service import CommonService
  21. class TaskService(CommonService):
  22. model = Task
  23. @classmethod
  24. @DB.connection_context()
  25. def get_tasks(cls, tm, mod=0, comm=1, items_per_page=64):
  26. 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]
  27. docs = cls.model.select(*fields) \
  28. .join(Document, on=(cls.model.doc_id == Document.id)) \
  29. .join(Knowledgebase, on=(Document.kb_id == Knowledgebase.id)) \
  30. .join(Tenant, on=(Knowledgebase.tenant_id == Tenant.id))\
  31. .where(
  32. Document.status == StatusEnum.VALID.value,
  33. ~(Document.type == FileType.VIRTUAL.value),
  34. cls.model.progress == 0,
  35. cls.model.update_time >= tm,
  36. (Expression(cls.model.create_time, "%%", comm) == mod))\
  37. .order_by(cls.model.update_time.asc())\
  38. .paginate(1, items_per_page)
  39. return list(docs.dicts())
  40. @classmethod
  41. @DB.connection_context()
  42. def do_cancel(cls, id):
  43. try:
  44. cls.model.get_by_id(id)
  45. return False
  46. except Exception as e:
  47. pass
  48. return True