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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 random
  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.settings import cron_logger
  22. from rag.utils.minio_conn import MINIO
  23. from rag.utils.redis_conn import REDIS_CONN
  24. def collect():
  25. doc_locations = TaskService.get_ongoing_doc_name()
  26. print(doc_locations)
  27. if len(doc_locations) == 0:
  28. time.sleep(1)
  29. return
  30. return doc_locations
  31. def main():
  32. locations = collect()
  33. if not locations:return
  34. print("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):continue
  41. file_bin = MINIO.get(kb_id, loc)
  42. REDIS_CONN.transaction(key, file_bin, 12 * 60)
  43. cron_logger.info("CACHE: {}".format(loc))
  44. except Exception as e:
  45. traceback.print_stack(e)
  46. except Exception as e:
  47. traceback.print_stack(e)
  48. if __name__ == "__main__":
  49. while True:
  50. main()
  51. close_connection()
  52. time.sleep(1)