Skip to content
Snippets Groups Projects

Support feature worker declaration from gitlab.teklia.com

Merged Valentin Rigal requested to merge teklia-workers into release-1.7.1
All threads resolved!
1 file
+ 18
3
Compare changes
  • Side-by-side
  • Inline
from collections import defaultdict
from django.conf import settings
from django.core.management.base import BaseCommand, CommandError
from django.db import transaction
from django.db.models import Max
from teklia_toolbox.config import ConfigParser
from teklia_toolbox.config import ConfigParser, ConfigurationError
from arkindex.process.models import ArkindexFeature, FeatureUsage, Worker, WorkerType, WorkerVersion, WorkerVersionState
@@ -17,12 +19,25 @@ def parse_config():
feature_parser = features_parser.add_subparser(feature.value, allow_extra_keys=False, default={})
feature_parser.add_option("image", type=str, default=None)
feature_parser.add_option("command", type=str, default=None)
teklia_worker_parser = feature_parser.add_subparser("teklia_worker", allow_extra_keys=False, default={})
teklia_worker_parser = feature_parser.add_subparser("teklia_worker", allow_extra_keys=False, default=None)
teklia_worker_parser.add_option("name", type=str, default=None)
teklia_worker_parser.add_option("version", type=str, default=None)
teklia_worker_parser.add_option("slug", type=str, default=None)
return parser.parse(settings.BASE_DIR / "system_workers.yml")
parsed = parser.parse(settings.BASE_DIR / "system_workers.yml")
errors = defaultdict(list)
for feature, config in parsed["features"].items():
if config["image"] and config["teklia_worker"]:
errors[feature].append("Exactly one of image/command or teklia_parser must be set")
continue
if (subparser := config["teklia_worker"]) and (None in subparser.values()):
errors[feature].append("teklia_parser configuration must define a name, a version and a slug")
if (config["command"] and config["image"] is None):
errors[feature].append("command argument must be set with the image argument")
if errors:
raise ConfigurationError(errors)
return parsed
class Command(BaseCommand):
Loading