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

delay_schedule.py 2.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # !/usr/bin/env python
  2. # -*- coding:utf-8 -*-
  3. """
  4. Copyright 2020 Tianshu AI Platform. All Rights Reserved.
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. =============================================================
  15. """
  16. import time
  17. import sched
  18. import threading
  19. import logging
  20. import script.delaytaskscript as delay_script
  21. from datetime import datetime
  22. schedule = sched.scheduler(time.time, time.sleep)
  23. class Start_thread:
  24. def start_thread(self):
  25. Redis_thread.processing_queue = self
  26. t = threading.Thread(target=delay_key_thread, args=())
  27. t.setDaemon(True)
  28. t.start()
  29. class Redis_thread:
  30. processing_queue = None
  31. redis_client_thread = None
  32. processing_key = None
  33. def delay_schedule(inc, ):
  34. """Delay task method.
  35. Args:
  36. self: scheduled task time.
  37. :param inc:
  38. """
  39. try:
  40. logging.info("delay:" + datetime.now().strftime("B%Y-%m-%d %H:%M:%S"))
  41. if Redis_thread.processing_key is not None:
  42. logging.info("执行一次delay操作")
  43. logging.info("---------------delay_key = %s", Redis_thread.processing_key)
  44. Redis_thread.redis_client_thread.eval(delay_script.delayTaskLua, 1, Redis_thread.processing_queue,
  45. Redis_thread.processing_key,
  46. int(time.time()))
  47. schedule.enter(inc, 0, delay_schedule, (inc,))
  48. except Exception as e:
  49. logging.info("delay error: %s", e)
  50. def delay_key_thread():
  51. """Delay task thread.
  52. Args:
  53. """
  54. schedule.enter(0, 0, delay_schedule, (5,))
  55. schedule.run()

一站式算法开发平台、高性能分布式深度学习框架、先进算法模型库、视觉模型炼知平台、数据可视化分析平台等一系列平台及工具,在模型高效分布式训练、数据处理和可视分析、模型炼知和轻量化等技术上形成独特优势,目前已在产学研等各领域近千家单位及个人提供AI应用赋能

Contributors (1)