|
36 | 36 | from ..utils.task_queue import TaskQueue |
37 | 37 | from ..version import __version__ |
38 | 38 | from ..wallet import singletons |
39 | | -from ..wallet.anoncreds_upgrade import check_upgrade_completion_loop |
| 39 | +from ..wallet.anoncreds_upgrade import ( |
| 40 | + UPGRADING_RECORD_IN_PROGRESS, |
| 41 | + check_upgrade_completion_loop, |
| 42 | +) |
40 | 43 | from .base_server import BaseAdminServer |
41 | 44 | from .error import AdminSetupError |
42 | 45 | from .request_context import AdminRequestContext |
@@ -214,28 +217,30 @@ async def upgrade_middleware(request: web.BaseRequest, handler: Coroutine): |
214 | 217 | storage = session.inject(BaseStorage) |
215 | 218 | upgrade_initiated = await storage.find_all_records(RECORD_TYPE_ACAPY_UPGRADING) |
216 | 219 | if upgrade_initiated: |
217 | | - # If we get here, than another instance started an upgrade |
218 | | - # We need to check for completion (or fail) in another process |
219 | | - in_progress_upgrades.set_wallet(context.profile.name) |
220 | | - is_subwallet = context.metadata and "wallet_id" in context.metadata |
221 | | - |
222 | | - # Create background task and store reference to prevent garbage collection |
223 | | - task = asyncio.create_task( |
224 | | - check_upgrade_completion_loop( |
225 | | - context.profile, |
226 | | - is_subwallet, |
| 220 | + # Check if the upgrade is actually in progress (not finished) |
| 221 | + if upgrade_initiated[0].value == UPGRADING_RECORD_IN_PROGRESS: |
| 222 | + # If we get here, than another instance started an upgrade |
| 223 | + # We need to check for completion (or fail) in another process |
| 224 | + in_progress_upgrades.set_wallet(context.profile.name) |
| 225 | + is_subwallet = context.metadata and "wallet_id" in context.metadata |
| 226 | + |
| 227 | + # Create background task and store reference to prevent garbage collection |
| 228 | + task = asyncio.create_task( |
| 229 | + check_upgrade_completion_loop( |
| 230 | + context.profile, |
| 231 | + is_subwallet, |
| 232 | + ) |
227 | 233 | ) |
228 | | - ) |
229 | 234 |
|
230 | | - # Store task reference on the app to prevent garbage collection |
231 | | - if not hasattr(request.app, "_background_tasks"): |
232 | | - request.app._background_tasks = set() |
233 | | - request.app._background_tasks.add(task) |
| 235 | + # Store task reference on the app to prevent garbage collection |
| 236 | + if not hasattr(request.app, "_background_tasks"): |
| 237 | + request.app._background_tasks = set() |
| 238 | + request.app._background_tasks.add(task) |
234 | 239 |
|
235 | | - # Remove task from set when it completes to prevent memory leaks |
236 | | - task.add_done_callback(request.app._background_tasks.discard) |
| 240 | + # Remove task from set when it completes to prevent memory leaks |
| 241 | + task.add_done_callback(request.app._background_tasks.discard) |
237 | 242 |
|
238 | | - raise web.HTTPServiceUnavailable(reason="Upgrade in progress") |
| 243 | + raise web.HTTPServiceUnavailable(reason="Upgrade in progress") |
239 | 244 |
|
240 | 245 | return await handler(request) |
241 | 246 |
|
|
0 commit comments