Skip to content
This repository has been archived by the owner on Jun 12, 2018. It is now read-only.

Commit

Permalink
Better contact migration output.
Browse files Browse the repository at this point in the history
  • Loading branch information
jerith committed May 12, 2014
1 parent 615d60e commit 5d47088
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
16 changes: 11 additions & 5 deletions go/scripts/migrate_contacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from twisted.python import usage
from twisted.internet import reactor
from twisted.internet.defer import (
maybeDeferred, DeferredQueue, inlineCallbacks)
maybeDeferred, DeferredQueue, inlineCallbacks, returnValue)
from vumi.service import Worker, WorkerCreator
from vumi.servicemaker import VumiOptions
import yaml
Expand Down Expand Up @@ -60,19 +60,25 @@ def migrate_contact(self, user_api, contact_key):
"Contact %s already migrated -- ignoring." % (contact_key,))
else:
yield contact.save()
returnValue(True)
returnValue(False)

@inlineCallbacks
def migrate_contacts_for_account(self, user_account_key):
user_api = self.vumi_api.get_user_api(user_account_key)
contact_keys = yield self.get_contact_keys(user_api)
contact_count = len(contact_keys)
migrated_count = 0
self.emit("Starting migration of %s contacts." % (contact_count,))
for i, contact_key in enumerate(contact_keys):
yield self.migrate_contact(user_api, contact_key)
migrated = yield self.migrate_contact(user_api, contact_key)
if migrated:
migrated_count += 1
if (i + 1) % 100 == 0:
self.emit("Contacts migrated: %s / %s" % (
i + 1, contact_count))
self.emit("Finished migrating %s contacts." % (contact_count,))
self.emit("Contacts migrated: %s (%s) / %s" % (
i + 1, migrated_count, contact_count))
self.emit("Finished processing %s contacts, %s migrated." % (
contact_count, migrated_count))

@inlineCallbacks
def startWorker(self):
Expand Down
25 changes: 13 additions & 12 deletions go/scripts/tests/test_migrate_contacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,19 +157,20 @@ def generate_contact_keys(user_api):
return ['contact%03s' % i for i in xrange(1000)]

worker.get_contact_keys = generate_contact_keys
worker.migrate_contact = lambda user_api, contact_key: None
worker.migrate_contact = lambda user_api, contact_key: (
not contact_key.endswith('0'))
yield worker.migrate_contacts_for_account(user.account_key)
self.assertEqual(worker.stdout.getvalue(), ''.join([
'Starting migration of 1000 contacts.\n',
'Contacts migrated: 100 / 1000\n',
'Contacts migrated: 200 / 1000\n',
'Contacts migrated: 300 / 1000\n',
'Contacts migrated: 400 / 1000\n',
'Contacts migrated: 500 / 1000\n',
'Contacts migrated: 600 / 1000\n',
'Contacts migrated: 700 / 1000\n',
'Contacts migrated: 800 / 1000\n',
'Contacts migrated: 900 / 1000\n',
'Contacts migrated: 1000 / 1000\n',
'Finished migrating 1000 contacts.\n',
'Contacts migrated: 100 (90) / 1000\n',
'Contacts migrated: 200 (180) / 1000\n',
'Contacts migrated: 300 (270) / 1000\n',
'Contacts migrated: 400 (360) / 1000\n',
'Contacts migrated: 500 (450) / 1000\n',
'Contacts migrated: 600 (540) / 1000\n',
'Contacts migrated: 700 (630) / 1000\n',
'Contacts migrated: 800 (720) / 1000\n',
'Contacts migrated: 900 (810) / 1000\n',
'Contacts migrated: 1000 (900) / 1000\n',
'Finished processing 1000 contacts, 900 migrated.\n',
]))

0 comments on commit 5d47088

Please sign in to comment.