Report unavailable feature setup queues as retryable
This commit is contained in:
1 parent
5d62deafc3
commit
db8bd69bbf
3 files changed
+61
-16
No files matched your search
@@ -185,8 +185,17 @@ class FeatureConfigurationView(UserPassesTestMixin, FormView):
|
|||||||
section = self.kwargs.get("section")
|
section = self.kwargs.get("section")
|
||||||
form = kwargs.pop("form", None) or self.get_form()
|
form = kwargs.pop("form", None) or self.get_form()
|
||||||
targets = self.setup_targets(form)
|
targets = self.setup_targets(form)
|
||||||
|
section_settings = (
|
||||||
|
OPERATOR_FEATURE_SECTIONS[section][1] if section else None
|
||||||
|
)
|
||||||
jobs = OperatorOperation.objects.filter(
|
jobs = OperatorOperation.objects.filter(
|
||||||
action="feature-enable",
|
action="feature-enable",
|
||||||
|
target__in=[
|
||||||
|
key
|
||||||
|
for key, feature in LOCAL_FEATURES.items()
|
||||||
|
if section_settings is None
|
||||||
|
or feature.setting in section_settings
|
||||||
|
],
|
||||||
).order_by("-pk")
|
).order_by("-pk")
|
||||||
latest = {}
|
latest = {}
|
||||||
for job in jobs[:20]:
|
for job in jobs[:20]:
|
||||||
@@ -201,19 +210,14 @@ class FeatureConfigurationView(UserPassesTestMixin, FormView):
|
|||||||
selected_section=section,
|
selected_section=section,
|
||||||
form=form,
|
form=form,
|
||||||
setup_features=setup,
|
setup_features=setup,
|
||||||
setup_jobs=(
|
setup_jobs=[
|
||||||
[
|
(
|
||||||
(
|
job,
|
||||||
job,
|
labels[LOCAL_FEATURES[job.target].setting],
|
||||||
labels[LOCAL_FEATURES[job.target].setting],
|
package_operation_pending(job),
|
||||||
package_operation_pending(job),
|
)
|
||||||
)
|
for job in jobs[:5]
|
||||||
for job in jobs[:5]
|
],
|
||||||
if job.target in LOCAL_FEATURES
|
|
||||||
]
|
|
||||||
if section != "general"
|
|
||||||
else ()
|
|
||||||
),
|
|
||||||
settings_tabs=tuple(
|
settings_tabs=tuple(
|
||||||
(key, label)
|
(key, label)
|
||||||
for key, (label, _) in OPERATOR_FEATURE_SECTIONS.items()
|
for key, (label, _) in OPERATOR_FEATURE_SECTIONS.items()
|
||||||
@@ -261,7 +265,9 @@ class FeatureConfigurationView(UserPassesTestMixin, FormView):
|
|||||||
messages.error(request, "Wait for the current feature setup.")
|
messages.error(request, "Wait for the current feature setup.")
|
||||||
else:
|
else:
|
||||||
queue_operator_request(
|
queue_operator_request(
|
||||||
request.user, OperatorRequest("feature-enable", target)
|
request.user,
|
||||||
|
OperatorRequest("feature-enable", target),
|
||||||
|
retryable=True,
|
||||||
)
|
)
|
||||||
messages.success(request, "Feature setup queued.")
|
messages.success(request, "Feature setup queued.")
|
||||||
return redirect(request.path)
|
return redirect(request.path)
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ from django.utils.decorators import method_decorator
|
|||||||
from django.utils.functional import cached_property
|
from django.utils.functional import cached_property
|
||||||
from django.views.decorators.cache import never_cache
|
from django.views.decorators.cache import never_cache
|
||||||
from django.views.generic import FormView, TemplateView
|
from django.views.generic import FormView, TemplateView
|
||||||
|
from kombu.exceptions import OperationalError
|
||||||
|
|
||||||
from coulobre import remote_deployment
|
from coulobre import remote_deployment
|
||||||
from coulobre.local_update import DEB_WHEEL
|
from coulobre.local_update import DEB_WHEEL
|
||||||
@@ -44,7 +45,7 @@ def package_operation_pending(job):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def queue_operator_request(user, spec, *, source=None):
|
def queue_operator_request(user, spec, *, source=None, retryable=False):
|
||||||
job = OperatorOperation.objects.create(
|
job = OperatorOperation.objects.create(
|
||||||
actor=user,
|
actor=user,
|
||||||
action=spec.action,
|
action=spec.action,
|
||||||
@@ -52,7 +53,21 @@ def queue_operator_request(user, spec, *, source=None):
|
|||||||
plan=spec.plan,
|
plan=spec.plan,
|
||||||
source=source,
|
source=source,
|
||||||
)
|
)
|
||||||
transaction.on_commit(lambda: run_operator_operation.delay(job.pk))
|
|
||||||
|
def dispatch():
|
||||||
|
try:
|
||||||
|
run_operator_operation.delay(job.pk)
|
||||||
|
except OperationalError:
|
||||||
|
if not retryable:
|
||||||
|
raise
|
||||||
|
OperatorOperation.objects.filter(
|
||||||
|
pk=job.pk, started_at__isnull=True, finished_at__isnull=True
|
||||||
|
).update(
|
||||||
|
finished_at=timezone.now(),
|
||||||
|
problem="The operator queue is unavailable. Try again.",
|
||||||
|
)
|
||||||
|
|
||||||
|
transaction.on_commit(dispatch)
|
||||||
|
|
||||||
|
|
||||||
class ServerUpdateForm(forms.Form):
|
class ServerUpdateForm(forms.Form):
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ from django.contrib.auth import get_user_model
|
|||||||
from django.test import TestCase, override_settings
|
from django.test import TestCase, override_settings
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django_otp.plugins.otp_totp.models import TOTPDevice
|
from django_otp.plugins.otp_totp.models import TOTPDevice
|
||||||
|
from kombu.exceptions import OperationalError
|
||||||
|
|
||||||
from .installation_features import FEATURES
|
from .installation_features import FEATURES
|
||||||
from .models import (
|
from .models import (
|
||||||
@@ -92,6 +93,29 @@ class FeatureConfigurationTests(TestCase):
|
|||||||
self.assertEqual(operation.actor, self.operator)
|
self.assertEqual(operation.actor, self.operator)
|
||||||
queue.assert_called_once_with(operation.pk)
|
queue.assert_called_once_with(operation.pk)
|
||||||
|
|
||||||
|
@override_settings(LOCAL_WEB_ACTIVATION=True, WEB_FILE_MANAGER=False)
|
||||||
|
def test_feature_setup_can_retry_after_the_broker_is_offline(self):
|
||||||
|
self.sign_in()
|
||||||
|
path = reverse("panel:operator_settings", args=["server"])
|
||||||
|
module = "coulobre.hosting.installation_views"
|
||||||
|
with (
|
||||||
|
patch(f"{module}.Path"),
|
||||||
|
patch(f"{module}.PACKAGE_ASSETS"),
|
||||||
|
patch(
|
||||||
|
"coulobre.hosting.operator_tools.run_operator_operation.delay",
|
||||||
|
side_effect=OperationalError("offline"),
|
||||||
|
),
|
||||||
|
self.captureOnCommitCallbacks(execute=True),
|
||||||
|
):
|
||||||
|
self.assertEqual(
|
||||||
|
self.client.post(
|
||||||
|
path, {"setup_feature": "website-files"}
|
||||||
|
).status_code,
|
||||||
|
302,
|
||||||
|
)
|
||||||
|
self.assertEqual(OperatorOperation.objects.get().state, "failed")
|
||||||
|
self.assertContains(self.client.get(path), "Try again.")
|
||||||
|
|
||||||
def test_paused_backup_option_blocks_new_jobs_but_archives_stay_visible(
|
def test_paused_backup_option_blocks_new_jobs_but_archives_stay_visible(
|
||||||
self,
|
self,
|
||||||
):
|
):
|
||||||
|
|||||||
Reference in new issue
Block a user