cron.py 771 B

12345678910111213141516171819202122232425262728293031323334353637
  1. # -*- coding: utf-8 -*-
  2. """
  3. demeter web
  4. name:cron.py
  5. author:rabin
  6. """
  7. import time
  8. from demeter.core import *
  9. from multiprocessing import Process
  10. from gevent import monkey; monkey.patch_socket()
  11. import gevent
  12. timeSleep = 10
  13. def run(site, product):
  14. site['product'] = product
  15. service = Demeter.service(site['name'])
  16. service.init(site)
  17. service.start()
  18. def handle(data):
  19. task = []
  20. product = Demeter.service('product')
  21. for v in data:
  22. product.status(v['id'], 2)
  23. site = product.getSite(v['site_id'])
  24. task.append(gevent.spawn(run, site, [v]))
  25. gevent.joinall(task)
  26. def start(number = 1):
  27. while 1:
  28. product = Demeter.service('product')
  29. data = product.get()
  30. if data:
  31. p = Process(target=handle, args=(data,))
  32. p.start()
  33. time.sleep(timeSleep)
  34. start()