Skip to content

[WIP] - Aquire locks during onElement and onModel api's#284

Draft
DanRod1999 wants to merge 20 commits intoitwinjs-v5from
dan/make-async-to-aquire-locks
Draft

[WIP] - Aquire locks during onElement and onModel api's#284
DanRod1999 wants to merge 20 commits intoitwinjs-v5from
dan/make-async-to-aquire-locks

Conversation

@DanRod1999
Copy link
Copy Markdown
Contributor

@DanRod1999 DanRod1999 commented Mar 6, 2026

Trying to resolve: #263

Make onElement...() and onModel...() apis async. Add transformer option to acquire locks when these functions are called. If the transformation fails abandon changes and release locks acquired during transformation process, but only do so if the option flag for acquiring locks is set.

@DanRod1999 DanRod1999 linked an issue Mar 9, 2026 that may be closed by this pull request
@DanRod1999 DanRod1999 changed the title [WIP] - Make some importer functions async [WIP] - Make onElement and onModel api's async Mar 10, 2026
@DanRod1999

This comment was marked as outdated.

This comment was marked as outdated.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR advances the transformer’s async API migration (notably model export/import and delete callbacks) and introduces an option to automatically acquire element locks during import/provenance updates to support hub-locked workflows (per issue #263).

Changes:

  • Make IModelExportHandler.onExportModel async and update exporter flow to await it.
  • Make IModelImporter model/element/aspect import + element delete APIs async, updating transformer + test overrides accordingly.
  • Add an aquireElementLocks option and a new hub test that exercises transformation with locks enabled.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
packages/transformer/src/IModelExporter.ts Makes onExportModel async and awaits handler execution during export.
packages/transformer/src/IModelImporter.ts Converts key import/delete APIs to async and adds optional lock acquisition during import.
packages/transformer/src/IModelTransformer.ts Awaits importer calls, adds transformer-level lock behavior for provenance aspects, and plumbs new option into importer.
packages/transformer/src/test/IModelTransformerUtils.ts Updates importer/exporter subclasses to match new async method signatures.
packages/transformer/src/test/standalone/IModelTransformer.test.ts Updates test export handler override for async onExportModel.
packages/transformer/src/test/standalone/IModelTransformerHub.test.ts Adds lock-enabled end-to-end hub test and updates helper to support lock/no-lock creation.
common/api/imodel-transformer.api.md Updates public API declarations for new async signatures and new lock option.
Comments suppressed due to low confidence (1)

packages/transformer/src/IModelImporter.ts:233

  • With aquireElementLocks enabled, onInsertModel currently doesn't acquire any lock before calling models.insertModel, while update/delete do. If locks are required by the hub, inserting models may fail. Consider acquiring the appropriate lock(s) for the model's id/modeledElement before insertion (consistent with onUpdateModel/onDeleteModel).
  protected async onInsertModel(modelProps: ModelProps): Promise<Id64String> {
    try {
      const modelId: Id64String = this.targetDb.models.insertModel(modelProps);
      Logger.logInfo(
        loggerCategory,
        `Inserted ${this.formatModelForLogger(modelProps)}`
      );
      this.trackProgress();
      return modelId;
    } catch (error) {

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/transformer/src/IModelTransformer.ts Outdated
Comment thread packages/transformer/src/IModelTransformer.ts Outdated
Comment thread packages/transformer/src/IModelTransformer.ts Outdated
Comment thread packages/transformer/src/IModelTransformer.ts Outdated
Comment thread packages/transformer/src/IModelTransformer.ts Outdated
Comment thread packages/transformer/src/IModelTransformer.ts Outdated
Comment thread packages/transformer/src/IModelImporter.ts Outdated
Comment thread packages/transformer/src/IModelImporter.ts Outdated
Comment thread common/api/imodel-transformer.api.md Outdated
Comment thread packages/transformer/src/test/standalone/IModelTransformerHub.test.ts Outdated
@DanRod1999 DanRod1999 changed the title [WIP] - Make onElement and onModel api's async [WIP] - Aquire locks during onElement and onModel api's Apr 15, 2026
@DanRod1999 DanRod1999 requested a review from Copilot April 15, 2026 15:51
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 13 changed files in this pull request and generated 4 comments.

Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/transformer/src/IModelTransformer.ts Outdated
Comment thread packages/transformer/src/IModelTransformer.ts
Comment thread packages/transformer/src/IModelTransformer.ts
Comment thread packages/transformer/src/IModelImporter.ts
@mindaugasdirg
Copy link
Copy Markdown
Contributor

If option is enabled, we should also acquire schema lock in processSchemas() call too.

@DanRod1999
Copy link
Copy Markdown
Contributor Author

If option is enabled, we should also acquire schema lock in processSchemas() call too.

If the schema lock is needed that means we would be locking the entire imodel anyway right? Does that change anything? It slightly defeats the purpose of only locking what you need, but I guess in cases where they need to processSchema() there's no way to avoid it anyway

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Acquire locks when importing elements

4 participants