Пример #1
0
    def __delete_backup_in_bq_and_update_datastore(self, backup):
        try:
            table_reference = TableReference(configuration.backup_project_id,
                                             backup.dataset_id,
                                             backup.table_id)

            self.big_query_service.delete_table(table_reference)
            logging.debug(
                u"Table %s deleted from BigQuery. "
                u"Updating datastore. Retention policy used: '%s'",
                table_reference,
                type(self.policy).__name__)
            Backup.mark_backup_deleted(backup.key)
        except TableNotFoundException:
            Backup.mark_backup_deleted(backup.key)
            logging.warning(
                u"Table '%s' was not found. But we updated datastore anyway",
                backup.table_id)
        except HttpError as ex:
            error_message = u"Unexpected HttpError occurred while deleting " \
                            u"table '{}', error: {}: {}"\
                .format(backup.table_id, type(ex), ex)
            logging.exception(error_message)
        except Exception as ex:
            error_message = u"Could not delete backup '{}' error: {}: {}"\
                .format(backup.table_id, type(ex), ex)
            logging.exception(error_message)
Пример #2
0
 def test_deleting_backup_is_adding_current_timestamp_in_deleted_field(
         self):
     # given
     table = Table(project_id='example-proj-name',
                   dataset_id='example-dataset-name',
                   table_id='example-table-name',
                   last_checked=datetime(2017, 02, 1, 16, 30))
     backup = Backup(parent=table.key,
                     last_modified=datetime(2017, 02, 1, 16, 30),
                     created=datetime(2017, 02, 1, 16, 30),
                     dataset_id='targetDatasetId',
                     table_id='targetTableId',
                     numBytes=1234)
     backup.put()
     # when
     Backup.mark_backup_deleted(backup.key)
     # then
     deleted_backup = Backup.get_by_key(backup.key)
     self.assertEqual(deleted_backup.deleted, datetime(2017, 02, 3, 16, 30))