Put savepoints in the on_commit_queue so we can cancel on rb.
This commit is contained in:
		
							parent
							
								
									faacf7b594
								
							
						
					
					
						commit
						26141f8198
					
				
					 1 changed files with 9 additions and 2 deletions
				
			
		|  | @ -693,9 +693,10 @@ class PDBSQLMixin: | ||||||
|             self.ephemeral_directory.cleanup() |             self.ephemeral_directory.cleanup() | ||||||
| 
 | 
 | ||||||
|     def commit(self): |     def commit(self): | ||||||
|         while self.on_commit_queue: |         while len(self.on_commit_queue) > 0: | ||||||
|             task = self.on_commit_queue.pop() |             task = self.on_commit_queue.pop() | ||||||
|             print(task) |             if isinstance(task, str): | ||||||
|  |                 continue | ||||||
|             args = task.get('args', []) |             args = task.get('args', []) | ||||||
|             kwargs = task.get('kwargs', {}) |             kwargs = task.get('kwargs', {}) | ||||||
|             task['action'](*args, **kwargs) |             task['action'](*args, **kwargs) | ||||||
|  | @ -711,6 +712,7 @@ class PDBSQLMixin: | ||||||
|             self.log.debug('Final rollback.') |             self.log.debug('Final rollback.') | ||||||
|             self.sql.rollback() |             self.sql.rollback() | ||||||
|             self.savepoints.clear() |             self.savepoints.clear() | ||||||
|  |             self.on_commit_queue.clear() | ||||||
|             return |             return | ||||||
| 
 | 
 | ||||||
|         cur = self.sql.cursor() |         cur = self.sql.cursor() | ||||||
|  | @ -718,6 +720,10 @@ class PDBSQLMixin: | ||||||
|         self.log.debug('Rolling back to %s', restore_to) |         self.log.debug('Rolling back to %s', restore_to) | ||||||
|         query = 'ROLLBACK TO "%s"' % restore_to |         query = 'ROLLBACK TO "%s"' % restore_to | ||||||
|         cur.execute(query) |         cur.execute(query) | ||||||
|  |         while len(self.on_commit_queue) > 0: | ||||||
|  |             item = self.on_commit_queue.pop(-1) | ||||||
|  |             if item == restore_to: | ||||||
|  |                 break | ||||||
| 
 | 
 | ||||||
|     def savepoint(self): |     def savepoint(self): | ||||||
|         savepoint_id = helpers.random_hex(length=16) |         savepoint_id = helpers.random_hex(length=16) | ||||||
|  | @ -725,6 +731,7 @@ class PDBSQLMixin: | ||||||
|         query = 'SAVEPOINT "%s"' % savepoint_id |         query = 'SAVEPOINT "%s"' % savepoint_id | ||||||
|         self.sql.execute(query) |         self.sql.execute(query) | ||||||
|         self.savepoints.append(savepoint_id) |         self.savepoints.append(savepoint_id) | ||||||
|  |         self.on_commit_queue.append(savepoint_id) | ||||||
|         return savepoint_id |         return savepoint_id | ||||||
| 
 | 
 | ||||||
|     def sql_delete(self, table, pairs, *, commit=False): |     def sql_delete(self, table, pairs, *, commit=False): | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue