config.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # -*- coding: utf-8 -*-
  2. # @Author : YY
  3. from concurrent.futures import ThreadPoolExecutor
  4. from datetime import timedelta
  5. from ruoyi_common.ruoyi.config import CONFIG_CACHE
  6. class TokenConfig:
  7. header = CONFIG_CACHE["token.header"]
  8. secret = CONFIG_CACHE["token.secret"]
  9. _expire_time = CONFIG_CACHE["token.expireTime"]
  10. @classmethod
  11. def expire_time(cls) -> timedelta:
  12. """
  13. 获取过期时间
  14. Returns:
  15. timedelta: 过期时间
  16. """
  17. return timedelta(minutes=int(cls._expire_time))
  18. @classmethod
  19. def expire_seconds(cls) -> int:
  20. """
  21. 获取过期秒数
  22. Returns:
  23. int: 过期秒数
  24. """
  25. return int(cls.expire_time().total_seconds())
  26. class ThreadPoolConfig:
  27. max_pool_size = 200
  28. keep_alive_time = 300
  29. @classmethod
  30. def thread_pool(cls) -> ThreadPoolExecutor:
  31. """
  32. 获取线程池
  33. Returns:
  34. ThreadPoolExecutor: 线程池
  35. """
  36. ThreadPool = ThreadPoolExecutor(
  37. max_workers=cls.max_pool_size,
  38. thread_name_prefix='schedule-pool-%d',
  39. )
  40. return ThreadPool