PROJ/сельдерея: бегущие задачи опроса по результатам
celery.py
from __future__ import absolute_import
from kombu import Exchange, Queue
from celery import Celery
app = Celery('proj',
broker='redis://myredis.com',
backend='redis://myredis.com',
include=['proj.tasks'])
a_exchange = Exchange('a_ex', type='topic')
# Optional configuration, see the application user guide.
app.conf.update(
CELERY_TASK_RESULT_EXPIRES=3600,
CELERY_DISABLE_RATE_LIMITS=True,
CELERY_ROUTES = {"app.tasks.timeme": "a"}
)
if __name__ == '__main__':
app.start()
tasks.py
from __future__ import absolute_import
from proj.celery import app
import time
@app.task
def timeme(ts):
print 'hi'
lat = time.time() - float(ts)
return (lat, time.time())
do_tasks.py
import proj.tasks
import time
import sys
stime = time.time()
running = []
while time.time() < stime + 15:
res = proj.tasks.timeme.apply_async(args=[time.time()], link=proj.tasks.timeme.s())
running.append(res)
for res in running: #<------------ this gets extremely slow if running gets big!
if res.ready()
print res.get()
В приведенном выше коде , петля running
и посмотреть, готова ли она для результата или не требуется очень долгое время, так как running
становится все больше и больше.
Есть ли что-то вроде select.select
или poll/epoll
на выполнение задач сельдерея?
Так что я могу сделать что-то вроде следующего:
While running:
read, w, e = select.select([running], [], [])
print read.get()
running.remove(read)
break