signal now send_task's
This commit is contained in:
parent
d118d36e6e
commit
b1f4bb1a82
@ -1,15 +1,15 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
import argparse
|
import argparse
|
||||||
|
from celery.execute import send_task
|
||||||
|
|
||||||
from oyster.core import kernel
|
from oyster.core import kernel
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
description='do a task for all documents in a doc_class',
|
description='do a task for all documents in a doc_class',
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument('function', type=str, help='path to function 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')
|
||||||
|
|
||||||
@ -18,17 +18,8 @@ def main():
|
|||||||
docs = kernel.db.tracked.find({'doc_class': args.doc_class}, timeout=False)
|
docs = kernel.db.tracked.find({'doc_class': args.doc_class}, timeout=False)
|
||||||
print '%s docs in %s' % (docs.count(), args.doc_class)
|
print '%s docs in %s' % (docs.count(), args.doc_class)
|
||||||
|
|
||||||
path, func = args.function.rsplit('.', 1)
|
|
||||||
mod = __import__(path, fromlist=[func])
|
|
||||||
func = getattr(mod, func)
|
|
||||||
|
|
||||||
for doc in docs:
|
for doc in docs:
|
||||||
try:
|
send_task(task, doc['_id'])
|
||||||
func(doc, kernel.get_last_version(doc))
|
|
||||||
# make optional?
|
|
||||||
kernel.db.tracked.save(doc, safe=True)
|
|
||||||
except Exception as e:
|
|
||||||
print 'Error while processing %s: %s' % (doc, e)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
Loading…
Reference in New Issue
Block a user