Skip to content

Commit f3a9460

Browse files
[core][feat] Allows retrieving the model from plugins instead of db (#2232)
Co-authored-by: Lukas Lösche <lukas@some.engineering>
1 parent 303e661 commit f3a9460

File tree

4 files changed

+11
-13
lines changed

4 files changed

+11
-13
lines changed

.github/workflows/publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ jobs:
8181
continue-on-error: true
8282
shell: bash
8383
run: |
84-
yq '.services.fixworker.environment += "FIXWORKER_OVERRIDE=fixworker.collector=example"' docker-compose.yaml > docker-compose-model-gen.yaml
84+
yq '.services.fixcore.environment += "FIXCORE_MODEL_FROM_PLUGINS=true"' docker-compose.yaml > docker-compose-model-gen.yaml
8585
PSK= FIXCORE_ANALYTICS_OPT_OUT=true docker-compose -f docker-compose-model-gen.yaml up -d
8686
cd ${{ github.workspace }}/docs.fix.security/docs/resources
8787
python3 ${{ github.workspace }}/docs.fix.security/tools/export_models.py
@@ -345,7 +345,7 @@ jobs:
345345
continue-on-error: true
346346
shell: bash
347347
run: |
348-
yq '.services.fixworker.environment += "FIXWORKER_OVERRIDE=fixworker.collector=example"' docker-compose.yaml > docker-compose-model-gen.yaml
348+
yq '.services.fixcore.environment += "FIXCORE_MODEL_FROM_PLUGINS=true"' docker-compose.yaml > docker-compose-model-gen.yaml
349349
PSK= FIXCORE_ANALYTICS_OPT_OUT=true docker-compose -f docker-compose-model-gen.yaml up -d
350350
cd ${{ github.workspace }}/inventory.fix.security/versioned_docs/version-${{ steps.release.outputs.docsVersion }}/reference/unified-data-model
351351
python3 ${{ github.workspace }}/inventory.fix.security/tools/export_models.py

fixcore/fixcore/__main__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ async def direct_tenant(deps: TenantDependencies) -> None:
174174
deps.add(ServiceNames.system_data, db_change.current)
175175
message_bus = deps.add(ServiceNames.message_bus, MessageBus())
176176
scheduler = deps.add(ServiceNames.scheduler, APScheduler() if not config.args.no_scheduling else NoScheduler())
177-
model = deps.add(ServiceNames.model_handler, ModelHandlerDB(db, config.runtime.plantuml_server))
177+
model_handler_class = ModelHandlerFromCodeAndDB if config.args.model_from_plugins else ModelHandlerDB
178+
model = deps.add(ServiceNames.model_handler, model_handler_class(db, config.runtime.plantuml_server))
178179
worker_task_queue = deps.add(ServiceNames.worker_task_queue, WorkerTaskQueue())
179180
# a "real" config override deps.add, unlike the one used for core config
180181
config_override_service = deps.add(

fixcore/fixcore/system_start.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ def key_value(kv: str) -> Tuple[str, JsonElement]:
229229
choices=AllowedRoleNames,
230230
help="Assign this role to the service. Only takes effect when no PSK / UserManagement is used.",
231231
)
232+
# only valid in non-multi-tenant setup: generate model from plugins, instead of loading it from the database
233+
parser.add_argument("--model-from-plugins", default=False, action="store_true", help=argparse.SUPPRESS)
232234

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

fixlib/fixlib/core/model_export.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -265,16 +265,11 @@ def export_data_class(clazz: type) -> None:
265265
metadata["service"] = s
266266
if (slc := getattr(clazz, "categories", None)) and callable(slc) and (sl := slc()):
267267
metadata["categories"] = sl
268-
if (docs_url := getattr(clazz, "_docs_url", None)) and isinstance(docs_url, str):
269-
metadata["docs_url"] = docs_url
270-
if ( # only export kind description on aggregate roots
271-
with_kind_description
272-
and (ar := aggregate_root)
273-
and issubclass(clazz, ar)
274-
and (s := clazz.__dict__.get("_kind_description", None))
275-
and isinstance(s, str)
276-
):
277-
metadata["description"] = s
268+
if with_kind_description and (ar := aggregate_root) and issubclass(clazz, ar):
269+
if (s := clazz.__dict__.get("_kind_description", None)) and isinstance(s, str):
270+
metadata["description"] = s
271+
if (docs_url := getattr(clazz, "_docs_url", None)) and isinstance(docs_url, str):
272+
metadata["docs_url"] = docs_url
278273
if root and (source := model_source(clazz.__module__)):
279274
metadata["source"] = source
280275

0 commit comments

Comments
 (0)