add --sample to signal.py

This commit is contained in:
James Turk 2012-05-15 16:38:14 -04:00
parent 76e172da0f
commit 66acbde1d8
2 changed files with 13 additions and 2 deletions

View File

@ -26,3 +26,4 @@ class ElasticSearchPush(Task):
id=doc_id) id=doc_id)
except Exception as e: except Exception as e:
kernel.log(self.action, doc_id, error=True, exception=str(e)) kernel.log(self.action, doc_id, error=True, exception=str(e))
raise

View File

@ -1,6 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
import argparse import argparse
from celery.execute import send_task from celery.execute import send_task
from celery import current_app
from oyster.core import kernel from oyster.core import kernel
@ -12,6 +13,7 @@ def main():
parser.add_argument('task', type=str, help='task name to apply') parser.add_argument('task', type=str, help='task name to apply')
parser.add_argument('doc_class', type=str, parser.add_argument('doc_class', type=str,
help='doc_class to apply function to') help='doc_class to apply function to')
parser.add_argument('--sample', action='store_true')
args = parser.parse_args() args = parser.parse_args()
@ -20,6 +22,14 @@ def main():
}, timeout=False) }, timeout=False)
print '%s docs in %s' % (docs.count(), args.doc_class) print '%s docs in %s' % (docs.count(), args.doc_class)
if args.sample:
print 'sampling 100 documents'
docs = docs.limit(100)
task = current_app.tasks[name]
for doc in docs:
task.apply((doc['_id'],))
else:
for doc in docs: for doc in docs:
send_task(args.task, (doc['_id'], )) send_task(args.task, (doc['_id'], ))