cron.py 722 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import time
  4. from demeter.core import *
  5. from gevent import monkey; monkey.patch_socket()
  6. import gevent
  7. timeSleep = 15
  8. def command(file):
  9. return 'python '+File.path()+'convert.py -f ' + file
  10. # 文档转换
  11. def convert():
  12. r = Demeter.redis()
  13. c = Demeter.config['redis']
  14. i = 0
  15. while 1:
  16. file = r.lpop(c['name'])
  17. if file:
  18. g = command(file)
  19. Shell.popen(g, True, True)
  20. i = i+1
  21. if i >= 10:
  22. gevent.sleep(timeSleep)
  23. i = 0
  24. # 清理一天前的sign
  25. def signature():
  26. while 1:
  27. service = Demeter.service('convert')
  28. service.crearSignature()
  29. gevent.sleep(3600)
  30. def handle():
  31. gevent.joinall([
  32. gevent.spawn(convert),
  33. gevent.spawn(signature),
  34. ])
  35. handle()