print summary

This commit is contained in:
James Turk 2012-05-15 17:05:19 -04:00
parent f14fc1cd2b
commit b4de2ee0f9

View File

@ -1,5 +1,6 @@
#!/usr/bin/env python #!/usr/bin/env python
import argparse import argparse
import traceback
from celery.execute import send_task from celery.execute import send_task
from celery import current_app from celery import current_app
@ -28,11 +29,20 @@ def main():
docs = docs.limit(100) docs = docs.limit(100)
args.immediate = True args.immediate = True
total = docs.count()
errors = 0
if args.immediate: if args.immediate:
module, name = args.task.rsplit('.', 1) module, name = args.task.rsplit('.', 1)
task = getattr(__import__(module, fromlist=[name]), name) task = getattr(__import__(module, fromlist=[name]), name)
for doc in docs: for doc in docs:
try:
task.apply((doc['_id'],), throw=True) task.apply((doc['_id'],), throw=True)
except Exception:
errors += 1
traceback.print_exc()
print '{0} errors in {1} documents'.format(errors, total)
else: else:
for doc in docs: for doc in docs:
send_task(args.task, (doc['_id'], )) send_task(args.task, (doc['_id'], ))