Skip to content
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

Add documentation for propagators and how they are executed #1312

Merged
merged 2 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions internal/headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,24 @@ type HeaderReader interface {
ForEachKey(handler func(string, []byte) error) error
}

// ContextPropagator is an interface that determines what information from
// context to pass along
// ContextPropagator determines what information from context to pass along.
Copy link
Member

Choose a reason for hiding this comment

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

thanks for filling in this documentation gap. @shijiesheng can you review please?

//
// The information passed is called Headers - a sequence of string to []byte
// tuples of serialized data that should follow workflow and activity execution
// around.
//
// Inject* methods are used on the way from the process to persistence in
// Cadence - thus they use HeaderWriter-s to write the metadata. Extract*
// methods are used on the way from persisted state in Cadence to execution
// - thus they use HeaderReader-s to read the metadata and fill it in the
// returned context. Returning error from Extract* methods prevents the
// successful workflow run.
//
// The whole sequence of execution is:
//
// Process initiating the workflow -> Inject -> Cadence -> Go Workflow Worker
// -> ExtractToWorkflow -> Start executing a workflow -> InjectFromWorkflow ->
// Cadence -> Go Activity Worker -> Extract -> Execute Activity
Comment on lines +55 to +56
Copy link
Member

Choose a reason for hiding this comment

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

nit: this might make it easier for users to understand

Suggested change
// -> ExtractToWorkflow -> Start executing a workflow -> InjectFromWorkflow ->
// Cadence -> Go Activity Worker -> Extract -> Execute Activity
// -> ExtractToWorkflow -> Start executing a workflow -> Schedule an activity -> InjectFromWorkflow ->
// Cadence -> Go Activity Worker -> Extract -> Execute Activity

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that it is out of the scope of the context propagator, so we might add it if it causes confusion.

type ContextPropagator interface {
// Inject injects information from a Go Context into headers
Inject(context.Context, HeaderWriter) error
Expand Down
20 changes: 18 additions & 2 deletions workflow/context_propagator.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,23 @@ type (
// HeaderWriter is an interface to write information to cadence headers
HeaderWriter = internal.HeaderWriter

// ContextPropagator is an interface that determines what information from
// context to pass along
// ContextPropagator determines what information from context to pass along.
//
// The information passed is called Headers - a sequence of string to []byte
// tuples of serialized data that should follow workflow and activity execution
// around.
//
// Inject* methods are used on the way from the process to persistence in
// Cadence - thus they use HeaderWriter-s to write the metadata. Extract*
// methods are used on the way from persisted state in Cadence to execution
// - thus they use HeaderReader-s to read the metadata and fill it in the
// returned context. Returning error from Extract* methods prevents the
// successful workflow run.
//
// The whole sequence of execution is:
//
// Process initiating the workflow -> Inject -> Cadence -> Go Workflow Worker
// -> ExtractToWorkflow -> Start executing a workflow -> InjectFromWorkflow ->
Copy link
Member

Choose a reason for hiding this comment

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

ditto

// Cadence -> Go Activity Worker -> Extract -> Execute Activity
ContextPropagator = internal.ContextPropagator
)