cron.py 700 B

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