Skip to content

Commit

Permalink
[core][feat] Allows retrieving the model from plugins instead of db (#…
Browse files Browse the repository at this point in the history
…2232)

Co-authored-by: Lukas Lösche <[email protected]>
  • Loading branch information
aquamatthias and lloesche authored Oct 10, 2024
1 parent 303e661 commit f3a9460
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ jobs:
continue-on-error: true
shell: bash
run: |
yq '.services.fixworker.environment += "FIXWORKER_OVERRIDE=fixworker.collector=example"' docker-compose.yaml > docker-compose-model-gen.yaml
yq '.services.fixcore.environment += "FIXCORE_MODEL_FROM_PLUGINS=true"' docker-compose.yaml > docker-compose-model-gen.yaml
PSK= FIXCORE_ANALYTICS_OPT_OUT=true docker-compose -f docker-compose-model-gen.yaml up -d
cd ${{ github.workspace }}/docs.fix.security/docs/resources
python3 ${{ github.workspace }}/docs.fix.security/tools/export_models.py
Expand Down Expand Up @@ -345,7 +345,7 @@ jobs:
continue-on-error: true
shell: bash
run: |
yq '.services.fixworker.environment += "FIXWORKER_OVERRIDE=fixworker.collector=example"' docker-compose.yaml > docker-compose-model-gen.yaml
yq '.services.fixcore.environment += "FIXCORE_MODEL_FROM_PLUGINS=true"' docker-compose.yaml > docker-compose-model-gen.yaml
PSK= FIXCORE_ANALYTICS_OPT_OUT=true docker-compose -f docker-compose-model-gen.yaml up -d
cd ${{ github.workspace }}/inventory.fix.security/versioned_docs/version-${{ steps.release.outputs.docsVersion }}/reference/unified-data-model
python3 ${{ github.workspace }}/inventory.fix.security/tools/export_models.py
Expand Down
3 changes: 2 additions & 1 deletion fixcore/fixcore/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ async def direct_tenant(deps: TenantDependencies) -> None:
deps.add(ServiceNames.system_data, db_change.current)
message_bus = deps.add(ServiceNames.message_bus, MessageBus())
scheduler = deps.add(ServiceNames.scheduler, APScheduler() if not config.args.no_scheduling else NoScheduler())
model = deps.add(ServiceNames.model_handler, ModelHandlerDB(db, config.runtime.plantuml_server))
model_handler_class = ModelHandlerFromCodeAndDB if config.args.model_from_plugins else ModelHandlerDB
model = deps.add(ServiceNames.model_handler, model_handler_class(db, config.runtime.plantuml_server))
worker_task_queue = deps.add(ServiceNames.worker_task_queue, WorkerTaskQueue())
# a "real" config override deps.add, unlike the one used for core config
config_override_service = deps.add(
Expand Down
2 changes: 2 additions & 0 deletions fixcore/fixcore/system_start.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ def key_value(kv: str) -> Tuple[str, JsonElement]:
choices=AllowedRoleNames,
help="Assign this role to the service. Only takes effect when no PSK / UserManagement is used.",
)
# only valid in non-multi-tenant setup: generate model from plugins, instead of loading it from the database
parser.add_argument("--model-from-plugins", default=False, action="store_true", help=argparse.SUPPRESS)

parsed: Namespace = parser.parse_args(args if args else [])

Expand Down
15 changes: 5 additions & 10 deletions fixlib/fixlib/core/model_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,16 +265,11 @@ def export_data_class(clazz: type) -> None:
metadata["service"] = s
if (slc := getattr(clazz, "categories", None)) and callable(slc) and (sl := slc()):
metadata["categories"] = sl
if (docs_url := getattr(clazz, "_docs_url", None)) and isinstance(docs_url, str):
metadata["docs_url"] = docs_url
if ( # only export kind description on aggregate roots
with_kind_description
and (ar := aggregate_root)
and issubclass(clazz, ar)
and (s := clazz.__dict__.get("_kind_description", None))
and isinstance(s, str)
):
metadata["description"] = s
if with_kind_description and (ar := aggregate_root) and issubclass(clazz, ar):
if (s := clazz.__dict__.get("_kind_description", None)) and isinstance(s, str):
metadata["description"] = s
if (docs_url := getattr(clazz, "_docs_url", None)) and isinstance(docs_url, str):
metadata["docs_url"] = docs_url
if root and (source := model_source(clazz.__module__)):
metadata["source"] = source

Expand Down

0 comments on commit f3a9460

Please sign in to comment.