Skip to content

Commit

Permalink
Fix error handling in rocky when queue is full in Scheduler (1.12) (#…
Browse files Browse the repository at this point in the history
…1932)

Co-authored-by: Rieven <[email protected]>
Co-authored-by: Jan Klopper <[email protected]>
Co-authored-by: ammar92 <[email protected]>
  • Loading branch information
4 people authored Oct 18, 2023
1 parent 6228403 commit ac40fb5
Show file tree
Hide file tree
Showing 13 changed files with 461 additions and 161 deletions.
2 changes: 1 addition & 1 deletion rocky/katalogus/views/change_clearance_level.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def post(self, request, *args, **kwargs):
return self.get(request, *args, **kwargs)

self.run_boefje_for_oois(boefje=self.plugin, oois=self.oois)
messages.add_message(self.request, messages.SUCCESS, _("Scanning successfully scheduled."))

del request.session["selected_oois"] # delete session
return redirect(reverse("task_list", kwargs={"organization_code": self.organization.code}))

Expand Down
18 changes: 11 additions & 7 deletions rocky/katalogus/views/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from django.utils.translation import gettext_lazy as _
from requests import HTTPError, RequestException
from rest_framework.status import HTTP_404_NOT_FOUND
from tools.view_helpers import schedule_task

from katalogus.client import (
Boefje as KATalogusBoefje,
Expand All @@ -27,7 +28,7 @@
IndemnificationNotPresentException,
TrustedClearanceLevelTooLowException,
)
from rocky.scheduler import Boefje, BoefjeTask, Normalizer, NormalizerTask, QueuePrioritizedItem, RawData, client
from rocky.scheduler import Boefje, BoefjeTask, Normalizer, NormalizerTask, QueuePrioritizedItem, RawData
from rocky.views.mixins import OctopoesView

logger = getLogger(__name__)
Expand Down Expand Up @@ -73,19 +74,22 @@ def is_required_field(self, field: str) -> bool:
return self.plugin_schema and field in self.plugin_schema.get("required", [])


class NormalizerMixin:
class NormalizerMixin(OctopoesView):
"""
When a user wants to run a normalizer on a given set of raw data,
this mixin provides the method to construct the normalizer task for that data and run it.
"""

def run_normalizer(self, normalizer: KATalogusNormalizer, raw_data: RawData) -> None:
normalizer_task = NormalizerTask(
id=uuid4(), normalizer=Normalizer(id=normalizer.id, version=None), raw_data=raw_data
id=uuid4(),
normalizer=Normalizer.parse_obj(normalizer.dict()),
raw_data=raw_data,
)

item = QueuePrioritizedItem(id=normalizer_task.id, priority=1, data=normalizer_task)
client.push_task(f"normalizer-{self.organization.code}", item)
task = QueuePrioritizedItem(id=normalizer_task.id, priority=1, data=normalizer_task)

schedule_task(self.request, self.organization.code, task)


class BoefjeMixin(OctopoesView):
Expand All @@ -102,8 +106,8 @@ def run_boefje(self, katalogus_boefje: KATalogusBoefje, ooi: Optional[OOI]) -> N
organization=self.organization.code,
)

item = QueuePrioritizedItem(id=boefje_task.id, priority=1, data=boefje_task)
client.push_task(f"boefje-{self.organization.code}", item)
task = QueuePrioritizedItem(id=boefje_task.id, priority=1, data=boefje_task)
schedule_task(self.request, self.organization.code, task)

def run_boefje_for_oois(
self,
Expand Down
1 change: 0 additions & 1 deletion rocky/katalogus/views/plugin_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ def post(self, request, *args, **kwargs):
boefje=boefje,
oois=oois_with_clearance_level,
)
messages.add_message(self.request, messages.SUCCESS, _("Scanning successfully scheduled."))

if oois_without_clearance_level:
if not self.organization_member.has_perm("tools.can_set_clearance_level"):
Expand Down
41 changes: 24 additions & 17 deletions rocky/rocky/locale/it/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-09-12 15:49+0000\n"
"POT-Creation-Date: 2023-10-18 14:11+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -1716,10 +1716,6 @@ msgstr ""
msgid "Session has terminated, please select OOIs again."
msgstr ""

#: katalogus/views/change_clearance_level.py katalogus/views/plugin_detail.py
msgid "Scanning successfully scheduled."
msgstr ""

#: katalogus/views/change_clearance_level.py
msgid "Change clearance level"
msgstr ""
Expand Down Expand Up @@ -3039,13 +3035,36 @@ msgstr ""
msgid "Members"
msgstr ""

#: tools/view_helpers.py
msgid ""
"Your task is scheduled and will soon be started in the background. Results "
"will be added to the object list when they are in. It may take some time, a "
"refresh of the page may be needed to show the results."
msgstr ""

#: rocky/messaging.py
msgid ""
"You have trusted this member with a clearance level of L{}. This member "
"needs at least a clearance level of L{} in order to do a proper onboarding. "
"Edit this member and change the clearance level if necessary."
msgstr ""

#: rocky/scheduler.py
msgid "Connectivity issues with Mula."
msgstr ""

#: rocky/scheduler.py
msgid "Task queue is full, please try again later."
msgstr ""

#: rocky/scheduler.py
msgid "Task is invalid."
msgstr ""

#: rocky/scheduler.py
msgid "Task already queued."
msgstr ""

#: rocky/settings.py
msgid "Blue light"
msgstr ""
Expand Down Expand Up @@ -5206,18 +5225,6 @@ msgstr ""
msgid "Fetching tasks failed: no connection with scheduler"
msgstr ""

#: rocky/views/tasks.py
msgid "Task queue is full, please try again later."
msgstr ""

#: rocky/views/tasks.py
msgid "Task already queued."
msgstr ""

#: rocky/views/tasks.py
msgid "Task is invalid."
msgstr ""

#: rocky/views/upload_csv.py
msgid ""
"For URL object type, a column 'raw' with URL values is required, starting "
Expand Down
Loading

0 comments on commit ac40fb5

Please sign in to comment.