Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

cache_file_svr.py 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. import time
  17. import traceback
  18. from api.db.db_models import close_connection
  19. from api.db.services.task_service import TaskService
  20. from api.utils.log_utils import logger
  21. from rag.utils.storage_factory import STORAGE_IMPL
  22. from rag.utils.redis_conn import REDIS_CONN
  23. def collect():
  24. doc_locations = TaskService.get_ongoing_doc_name()
  25. logger.info(doc_locations)
  26. if len(doc_locations) == 0:
  27. time.sleep(1)
  28. return
  29. return doc_locations
  30. def main():
  31. locations = collect()
  32. if not locations:return
  33. logger.info(f"TASKS: {len(locations)}")
  34. for kb_id, loc in locations:
  35. try:
  36. if REDIS_CONN.is_alive():
  37. try:
  38. key = "{}/{}".format(kb_id, loc)
  39. if REDIS_CONN.exist(key):continue
  40. file_bin = STORAGE_IMPL.get(kb_id, loc)
  41. REDIS_CONN.transaction(key, file_bin, 12 * 60)
  42. logger.info("CACHE: {}".format(loc))
  43. except Exception as e:
  44. traceback.print_stack(e)
  45. except Exception as e:
  46. traceback.print_stack(e)
  47. if __name__ == "__main__":
  48. while True:
  49. main()
  50. close_connection()
  51. time.sleep(1)