-
Notifications
You must be signed in to change notification settings - Fork 205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
resources: Customizable contexts. #7678
resources: Customizable contexts. #7678
Conversation
Keep the actual constructors in a trait, but instantiate it when working with ledger code. This allows us to later introduce an extra "context" type parameter to ResourceOwner.
This replaces the concrete `ExecutionContext`. While it _can_ be an execution context, it really doesn't matter as long as we can get at one somehow. This is being introduced so we can wrap the context in a container, either for type tagging or to include extra information. Because our current context _is_ `ExecutionContext`, and an implicit is provided to extract it, we can end up with two ways to get the same value. We use shadowing to prevent this. This problem should go away in the near future when a new context type is added. CHANGELOG_BEGIN - [Integration Kit] The `ResourceOwner` type is now parameterized by a `Context`, which is filled in by the corresponding `Context` class in the _ledger-resources_ dependency. This allows us to pass extra information through resource acquisition. CHANGELOG_END
So we can add a logging context to it.
BTW, I tried to make it wrap a phantom-typed execution context (i.e. TLDR implicits make everything fun. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would approve, but this PR is too large in scope to be merged without at least a second review.
ledger/participant-integration-api/src/main/scala/platform/indexer/JdbcIndexer.scala
Outdated
Show resolved
Hide resolved
): Future[Unit] = { | ||
private def initOrCheckParticipantId( | ||
dao: LedgerDao, | ||
)(implicit resourceContext: ResourceContext): Future[Unit] = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's inconsistency in how you name your implicit resource contexts. I would recommend sticking to the naming you used here (resourceContext
), since we also have other contexts we pass around.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to keep it as resourceContext
except when it's the implicit parameter of a ResourceOwner#acquire
, in which case it's context
. Is this too confusing?
ledger/participant-integration-api/src/main/scala/platform/store/FlywayMigrations.scala
Show resolved
Hide resolved
...participant-integration-api/src/test/lib/scala/platform/store/dao/JdbcLedgerDaoBackend.scala
Outdated
Show resolved
Hide resolved
ledger/participant-integration-api/src/test/suite/scala/platform/apiserver/GrpcServerSpec.scala
Outdated
Show resolved
Hide resolved
libs-scala/resources/src/main/scala/com/digitalasset/resources/AbstractResourceOwner.scala
Outdated
Show resolved
Hide resolved
libs-scala/resources/src/main/scala/com/digitalasset/resources/HasExecutionContext.scala
Outdated
Show resolved
Hide resolved
I'm a bit worried this is getting a bit too clever. |
Co-Authored-By: Stefano Baghino <43749967+stefanobaghino-da@users.noreply.github.com>
Saves a few lines of code.
…sources/customizable-contexts
I came to the same conclusion and threw away that particular changeset. |
Try and use the right execution context where possible.
/azp run digital-asset.daml (macOS) |
No pipelines are associated with this pull request. |
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
You wish! 😂 |
Yeah, the answer to this question made me think we could get away with this. |
This wraps the resource acquisition execution context in a type, for a few reasons:
DirectExecutionContext
.Pull Request Checklist
CHANGELOG_BEGIN
andCHANGELOG_END
tagsNOTE: CI is not automatically run on non-members pull-requests for security
reasons. The reviewer will have to comment with
/AzurePipelines run
totrigger the build.