12345678910111213141516171819202122232425262728293031323334353637 |
- # -*- coding: utf-8 -*-
- """
- demeter web
- name:cron.py
- author:rabin
- """
- import time
- from demeter.core import *
- from multiprocessing import Process
- from gevent import monkey; monkey.patch_socket()
- import gevent
- timeSleep = 10
- def run(site, product):
- site['product'] = product
- service = Demeter.service(site['name'])
- service.init(site)
- service.start()
- def handle(data):
- task = []
- product = Demeter.service('product')
- for v in data:
- product.status(v['id'], 2)
- site = product.getSite(v['site_id'])
- task.append(gevent.spawn(run, site, [v]))
- gevent.joinall(task)
-
- def start(number = 1):
- while 1:
- product = Demeter.service('product')
- data = product.get()
- if data:
- p = Process(target=handle, args=(data,))
- p.start()
- time.sleep(timeSleep)
- start()
|