Skip to content

Commit

Permalink
Merge pull request #223 from Clever/embedded-allow-setting-execution-…
Browse files Browse the repository at this point in the history
…name

Embedded allow setting execution name
  • Loading branch information
Sayan- authored Oct 10, 2019
2 parents fbb011b + 921176b commit e6029ca
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 20 deletions.
13 changes: 7 additions & 6 deletions docs/definitions.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,13 @@
<a name="startworkflowrequest"></a>
### StartWorkflowRequest

|Name|Schema|
|---|---|
|**input** <br>*optional*|string|
|**namespace** <br>*optional*|string|
|**queue** <br>*optional*|string|
|**workflowDefinition** <br>*optional*|[WorkflowDefinitionRef](#workflowdefinitionref)|
|Name|Description|Schema|
|---|---|---|
|**idSuffix** <br>*optional*|idSuffix is exclusively used for embedded workflow-manager to append human readable information to the newly created workflow's ID. Workflow IDs are truncated to 80 characters, so some or all of the suffix may be lost|string|
|**input** <br>*optional*||string|
|**namespace** <br>*optional*||string|
|**queue** <br>*optional*||string|
|**workflowDefinition** <br>*optional*||[WorkflowDefinitionRef](#workflowdefinitionref)|


<a name="stateresource"></a>
Expand Down
2 changes: 1 addition & 1 deletion docs/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Orchestrator for AWS Step Functions


### Version information
*Version* : 0.11.0
*Version* : 0.11.1


### URI scheme
Expand Down
26 changes: 19 additions & 7 deletions embedded/embedded.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ New state machine:
}
workflow := &models.Workflow{
WorkflowSummary: models.WorkflowSummary{
ID: workflowID(stateMachineName),
ID: workflowID(stateMachineName, i.IDSuffix),
CreatedAt: strfmt.DateTime(time.Now()),
LastUpdated: strfmt.DateTime(time.Now()),
WorkflowDefinition: wd,
Expand Down Expand Up @@ -507,13 +507,25 @@ func (e *Embedded) NewWorkflowDefinition(ctx context.Context, i *models.NewWorkf
// The workflow ID will contain the state machine name.
// This is to support the implementation of `GetWorkflowByID`, which requires
// the state machine name in order to call `DescribeExecution` in the SFN API.
func workflowID(smName string) string {
return fmt.Sprintf("%s--%s", smName, shortUUID())
// It will append a suffix, trimming the length to abide the 80 character step functions limit
// https://docs.aws.amazon.com/step-functions/latest/apireference/API_StartExecution.html
// If a suffix isn't provided the generated ID will include the first 8 characters of a UUID
func workflowID(smName, suffix string) string {
if suffix == "" {
suffix = shortUUID()
}
id := fmt.Sprintf("%s--%s", smName, suffix)

// ensure the generated ID is within the 80 character limit
if len(id) > 80 {
return id[:80]
}
return id
}

type workflowIDParts struct {
SMName string
ShortUUID string
SMName string
Suffix string
}

func parseWorkflowID(wid string) (*workflowIDParts, error) {
Expand All @@ -522,8 +534,8 @@ func parseWorkflowID(wid string) (*workflowIDParts, error) {
return nil, errors.Errorf("expected workflowID two contain at least two parts: %s", wid)
}
return &workflowIDParts{
SMName: strings.Join(s[0:len(s)-1], "--"),
ShortUUID: s[len(s)-1],
SMName: strings.Join(s[0:len(s)-1], "--"),
Suffix: s[len(s)-1],
}, nil
}

Expand Down
3 changes: 3 additions & 0 deletions gen-go/models/start_workflow_request.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions gen-go/server/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ func (s *Server) Serve() error {
opentracing.Tag{Key: "deploy_env", Value: os.Getenv("_DEPLOY_ENV")},
opentracing.Tag{Key: "team_owner", Value: os.Getenv("_TEAM_OWNER")},
opentracing.Tag{Key: "pod_id", Value: os.Getenv("_POD_ID")},
opentracing.Tag{Key: "pod_shortname", Value: os.Getenv("_POD_SHORTNAME")},
opentracing.Tag{Key: "pod_account", Value: os.Getenv("_POD_ACCOUNT")},
opentracing.Tag{Key: "pod_region", Value: os.Getenv("_POD_REGION")},
},
Expand Down
2 changes: 2 additions & 0 deletions gen-js/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ interface GenericOptions {
logger?: Logger;
tracer?: Tracer;
circuit?: CircuitOptions;
serviceName?: string;
}

interface DiscoveryOptions {
Expand Down Expand Up @@ -232,6 +233,7 @@ type SLStateMachine = {
type SLStateType = ("Pass" | "Task" | "Choice" | "Wait" | "Succeed" | "Fail" | "Parallel");

type StartWorkflowRequest = {
idSuffix?: string;
input?: string;
namespace?: string;
queue?: string;
Expand Down
8 changes: 4 additions & 4 deletions gen-js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ class WorkflowManager {

if (options.discovery) {
try {
this.address = discovery("workflow-manager", "http").url();
this.address = discovery(options.serviceName || "workflow-manager", "http").url();
} catch (e) {
this.address = discovery("workflow-manager", "default").url();
this.address = discovery(options.serviceName || "workflow-manager", "default").url();
}
} else if (options.address) {
this.address = options.address;
Expand All @@ -193,7 +193,7 @@ class WorkflowManager {
if (options.logger) {
this.logger = options.logger;
} else {
this.logger = new kayvee.logger("workflow-manager-wagclient");
this.logger = new kayvee.logger((options.serviceName || "workflow-manager") + "-wagclient");
}
if (options.tracer) {
this.tracer = options.tracer;
Expand All @@ -202,7 +202,7 @@ class WorkflowManager {
}

const circuitOptions = Object.assign({}, defaultCircuitOptions, options.circuit);
this._hystrixCommand = commandFactory.getOrCreate("workflow-manager").
this._hystrixCommand = commandFactory.getOrCreate(options.serviceName || "workflow-manager").
errorHandler(this._hystrixCommandErrorHandler).
circuitBreakerForceClosed(circuitOptions.forceClosed).
requestVolumeRejectionThreshold(circuitOptions.maxConcurrentRequests).
Expand Down
2 changes: 1 addition & 1 deletion gen-js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "workflow-manager",
"version": "0.11.0",
"version": "0.11.1",
"description": "Orchestrator for AWS Step Functions",
"main": "index.js",
"dependencies": {
Expand Down
5 changes: 4 additions & 1 deletion swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ info:
description: Orchestrator for AWS Step Functions
# when changing the version here, make sure to
# re-run `make generate` to generate clients and server
version: 0.11.0
version: 0.11.1
x-npm-package: workflow-manager
schemes:
- http
Expand Down Expand Up @@ -592,6 +592,9 @@ definitions:
description: "tags: object with key-value pairs; keys and values should be strings"
additionalProperties:
type: object
idSuffix:
description: "idSuffix is exclusively used for embedded workflow-manager to append human readable information to the newly created workflow's ID. Workflow IDs are truncated to 80 characters, so some or all of the suffix may be lost"
type: string

WorkflowDefinitionRef:
type: object
Expand Down

0 comments on commit e6029ca

Please sign in to comment.