setup: Allow starting installation when package manager is busy

Allows multiple apps to be queued up for installation. The operation for
installing the package will wait for the package manager to become available.
Wait for 24 hours before giving up.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2022-07-29 16:35:16 -07:00 committed by James Valleroy
parent 4cb1477c0d
commit 492d3a463c
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
4 changed files with 10 additions and 15 deletions

View File

@ -9,6 +9,7 @@ import logging
import pathlib
import subprocess
import threading
import time
from typing import Optional, Union
import apt.cache
@ -403,6 +404,13 @@ def install(package_names, skip_recommends=False, force_configuration=None,
return
start_time = time.time()
while is_package_manager_busy():
if time.time() - start_time >= 24 * 3600: # One day
raise PackageException(_('Timeout waiting for package manager'))
time.sleep(3) # seconds
logger.info('Running install for app - %s, packages - %s',
operation.app_id, package_names)

View File

@ -176,10 +176,6 @@ def _run_first_setup():
def _run_regular_setup():
"""Run setup on all apps also installing required packages."""
# TODO show notification that upgrades are running
if package.is_package_manager_busy():
raise Exception('Package manager is busy.')
app_ids = _get_apps_for_regular_setup()
run_setup_on_apps(app_ids, allow_install=True)

View File

@ -34,14 +34,7 @@
<form class="form-install" action="" method="post">
{% csrf_token %}
{% if package_manager_is_busy %}
<div class="alert alert-warning" role="alert">
{% blocktrans trimmed %}
Another installation or upgrade is already running.
Please wait for a few moments before trying again.
{% endblocktrans %}
</div>
{% elif has_unavailable_packages %}
{% if has_unavailable_packages %}
<div class="alert alert-warning" role="alert">
{% blocktrans trimmed %}
This application is currently not available in your distribution.
@ -64,7 +57,7 @@
{% endif %}
<input type="submit" class="btn btn-md btn-primary" name="install"
{% if package_manager_is_busy or has_unavailable_packages %}
{% if has_unavailable_packages %}
disabled="disabled"
{% endif %}
{% if setup_state.value == 'needs-setup' %}

View File

@ -287,8 +287,6 @@ class SetupView(TemplateView):
# Perform expensive operation only if needed.
if not context['operations']:
context[
'package_manager_is_busy'] = package.is_package_manager_busy()
context[
'has_unavailable_packages'] = self._has_unavailable_packages(
app)