You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cache_file_svr.py 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 logging
  17. import time
  18. import traceback
  19. from api.db.db_models import close_connection
  20. from api.db.services.task_service import TaskService
  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. logging.debug(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:
  33. return
  34. logging.info(f"TASKS: {len(locations)}")
  35. for kb_id, loc in locations:
  36. try:
  37. if REDIS_CONN.is_alive():
  38. try:
  39. key = "{}/{}".format(kb_id, loc)
  40. if REDIS_CONN.exist(key):
  41. continue
  42. file_bin = STORAGE_IMPL.get(kb_id, loc)
  43. REDIS_CONN.transaction(key, file_bin, 12 * 60)
  44. logging.info("CACHE: {}".format(loc))
  45. except Exception as e:
  46. traceback.print_stack(e)
  47. except Exception as e:
  48. traceback.print_stack(e)
  49. if __name__ == "__main__":
  50. while True:
  51. main()
  52. close_connection()
  53. time.sleep(1)