Created
June 7, 2017 15:43
-
-
Save agaerig/5b55774cb1fde3879af9c9d1fb6ca790 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def send_to_copilot(self, id_list): | |
| item_list = self.get_queryset().filter(id__in=id_list) | |
| start = datetime.now() | |
| for item in item_list: | |
| mi = MigratedItem.objects.get_for_object(item) | |
| if mi is not None and self.force_create: | |
| mi.delete() | |
| mi = None | |
| if mi is None: | |
| mi = MigratedItem(migrated_object=item) | |
| mi.copilot_migration = {} | |
| try: | |
| existing = 'id' in mi.copilot_migration | |
| self._process_item(mi, item, existing) | |
| mi.success = True | |
| except Exception as e: | |
| self._output(1, u'ERROR processing item {}. Saving error on MigratedItem.'.format(item.id)) | |
| mi.notes = traceback.format_exc() | |
| mi.success = False | |
| # bail on JSON decode error since it likely means the server is | |
| # not able to handle our requests any more | |
| if type(e) is ValueError and 'JSON' in e.message: | |
| mi.save() | |
| # raise | |
| if mi.success: | |
| mi.notes = '' | |
| mi.save() | |
| end = datetime.now() | |
| self._output(2, 'Done processing in %s ' % (end - start,)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment