-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement system search attributes(global version, executingStateIds,…
… IwfWorkflowType) (#68)
- Loading branch information
1 parent
affce4f
commit de0d711
Showing
9 changed files
with
171 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package interpreter | ||
|
||
import "github.com/indeedeng/iwf/service" | ||
|
||
const globalChangeId = "global" | ||
const startingVersionUsingGlobalVersioning = 1 | ||
const maxOfAllVersions = startingVersionUsingGlobalVersioning | ||
|
||
// see https://stackoverflow.com/questions/73941723/what-is-a-good-way-pattern-to-use-temporal-cadence-versioning-api | ||
type globalVersioner struct { | ||
workflowProvider WorkflowProvider | ||
} | ||
|
||
func newGlobalVersionProvider(workflowProvider WorkflowProvider) *globalVersioner { | ||
return &globalVersioner{ | ||
workflowProvider: workflowProvider, | ||
} | ||
} | ||
|
||
func (p *globalVersioner) isAfterVersionOfUsingGlobalVersioning(ctx UnifiedContext) bool { | ||
version := p.workflowProvider.GetVersion(ctx, globalChangeId, 0, maxOfAllVersions) | ||
return version >= startingVersionUsingGlobalVersioning | ||
} | ||
|
||
func (p *globalVersioner) upsertGlobalVersionSearchAttribute(ctx UnifiedContext) error { | ||
return p.workflowProvider.UpsertSearchAttributes(ctx, map[string]interface{}{ | ||
service.SearchAttributeGlobalVersion: maxOfAllVersions, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package interpreter | ||
|
||
import ( | ||
"github.com/indeedeng/iwf/gen/iwfidl" | ||
"github.com/indeedeng/iwf/service" | ||
) | ||
|
||
type stateExecutingManager struct { | ||
ctx UnifiedContext | ||
provider WorkflowProvider | ||
|
||
stateIdCount map[string]int | ||
totalExecutingCount int | ||
} | ||
|
||
func newStateExecutingManager(ctx UnifiedContext, provider WorkflowProvider) *stateExecutingManager { | ||
return &stateExecutingManager{ | ||
ctx: ctx, | ||
provider: provider, | ||
stateIdCount: map[string]int{}, | ||
totalExecutingCount: 0, | ||
} | ||
} | ||
|
||
func (e *stateExecutingManager) startStates(states []iwfidl.StateMovement) error { | ||
needsUpdate := false | ||
for _, s := range states { | ||
e.stateIdCount[s.StateId]++ | ||
if e.stateIdCount[s.StateId] == 1 { | ||
// first time the stateId show up | ||
needsUpdate = true | ||
} | ||
} | ||
e.totalExecutingCount += len(states) | ||
if needsUpdate { | ||
return e.updateSearchAttribute() | ||
} | ||
return nil | ||
} | ||
|
||
func (e *stateExecutingManager) completeStates(state iwfidl.StateMovement) error { | ||
e.stateIdCount[state.StateId]-- | ||
e.totalExecutingCount -= 1 | ||
if e.stateIdCount[state.StateId] == 0 { | ||
delete(e.stateIdCount, state.StateId) | ||
return e.updateSearchAttribute() | ||
} | ||
return nil | ||
} | ||
|
||
func (e *stateExecutingManager) getTotalExecutingStates() int { | ||
return e.totalExecutingCount | ||
} | ||
|
||
func (e *stateExecutingManager) updateSearchAttribute() error { | ||
var executingStateIds []string | ||
for sid := range e.stateIdCount { | ||
executingStateIds = append(executingStateIds, sid) | ||
} | ||
return e.provider.UpsertSearchAttributes(e.ctx, map[string]interface{}{ | ||
service.SearchAttributeExecutingStateIds: executingStateIds, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters