Skip to content

Commit

Permalink
Add option to whitelist or blacklist processes
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorjerse committed Nov 17, 2023
1 parent f3a07a9 commit 80005da
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
20 changes: 10 additions & 10 deletions resolwe/flow/managers/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ def __init__(self, *args, **kwargs):
else:
connector_list = [flow_manager.get("NAME", DEFAULT_CONNECTOR)]

# Store the whitelist and blacklist for later use.
self._whitelist = settings.FLOW_PROCESSES_WHITELIST
self._blacklist = settings.FLOW_PROCESSES_BLACKLIST

# Pre-load all needed connectors.
self.connectors = {}
for module_name in connector_list:
Expand Down Expand Up @@ -669,16 +673,12 @@ def process_data_object(data: Data):

try:
queryset = Data.objects.filter(status=Data.STATUS_RESOLVING)

whitelist = json.loads(os.environ.get("RESOLWE_PROCESS_WHITELIST", "null"))
blacklist = json.loads(os.environ.get("RESOLWE_PROCESS_BLACKLIST", "null"))

if whitelist:
assert isinstance(whitelist, list)
queryset = queryset.filter(process__slug__in=whitelist)
if blacklist:
assert isinstance(blacklist, list)
queryset = queryset.exclude(process__slug__in=blacklist)
# Check if process is in the whitelist or blacklist. The blacklist has
# priority.
if self._whitelist:
queryset = queryset.filter(process__slug__in=self._whitelist)
if self._blacklist:
queryset = queryset.exclude(process__slug__in=self._blacklist)

if data_id is not None:
# Scan only given data object and its children.
Expand Down
13 changes: 13 additions & 0 deletions tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
Django settings for running tests for Resolwe package.
"""
import json
import os
import sys
from distutils.util import strtobool
from pathlib import Path

from decouple import Csv, config

from resolwe.__about__ import __version__

PROJECT_ROOT = Path(__file__).parent.resolve()
Expand Down Expand Up @@ -204,6 +207,16 @@

FLOW_PROCESSES_RUNTIMES = ("resolwe.process.runtime.Process",)

# Which processes to schedule (if not set, all).
FLOW_PROCESSES_WHITELIST = config(
"FLOW_PROCESSES_WHITELIST", default="null", cast=json.loads
)

# Which processes to ignore (by default, none).
FLOW_PROCESSES_BLACKLIST = config(
"FLOW_PROCESSES_BLACKLIST", default="null", cast=json.loads
)

FLOW_EXECUTOR = {
"NAME": "resolwe.flow.executors.docker",
"LISTENER_CONNECTION": LISTENER_CONNECTION,
Expand Down

0 comments on commit 80005da

Please sign in to comment.