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 SignalWithStart #621

Merged
merged 2 commits into from
Mar 28, 2018
Merged

Add SignalWithStart #621

merged 2 commits into from
Mar 28, 2018

Conversation

vancexu
Copy link
Contributor

@vancexu vancexu commented Mar 20, 2018

Currently, Cadence support sending signals to running workflows using Client SingalWorkflow APIs. However, if workflow is not running, either not started or already closed, SignalWorkflow will return error. So if user wants to make sure a signal is delivered, user needs to catch the error, start the workflow and then send signal again. It’s not convenient for user, also it requires additional calls to Cadence.
This CR create new API SignalWithStart to ensure signal delivery.

  • if workflow is running, it will signal success (same as existing SignalWorkflow behavior);
  • If workflow is not running, it will restart that workflow and then signal;
  • If workflow is not found, it will start workflow using input args and then signal

In this way, user can perform all these signal-start-signal in one call.

@@ -962,6 +962,22 @@ struct SignalWorkflowExecutionRequest {
70: optional binary control
}

struct SignalWithStartWorkflowExecutionRequest {
Copy link
Contributor

Choose a reason for hiding this comment

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

out of curiosity, why not just add the signal part to existing start workflow API?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a decision after design meeting. We prefer creating new API (and related requests) for such new cases. e.g. completeActivityByID is new instead of reuse.
But we still try best to reuse as much as possible.

@@ -470,8 +470,9 @@ func (h *Handler) StartWorkflowExecution(ctx context.Context,

response, err2 := engine.StartWorkflowExecution(wrappedRequest)
if err2 != nil {
h.updateErrorMetric(metrics.HistoryStartWorkflowExecutionScope, h.convertError(err2))
return nil, h.convertError(err2)
tmpErr := h.convertError(err2)
Copy link
Contributor

Choose a reason for hiding this comment

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

convertedErr?

if err0 != nil {
if _, ok := err0.(*workflow.EntityNotExistsError); ok {
isBrandNew = true
goto Start_And_Signal
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we use goto?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agree it might feel uncomfortable, removed.

}

// Generate first decision task event.
taskList := *request.TaskList.Name
Copy link
Contributor

Choose a reason for hiding this comment

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

GetName() if possible

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed

}
msBuilder.executionInfo.LastFirstEventID = startedEvent.GetEventId()

createWorkflow := func(isBrandNew bool, prevRunID string) (string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this func does not take the workflow ID reuse policy in consideration.
moreover, it is hard to actually maintain a second set of start workflow logic.
so could we actually merge the signal & start to start workflow API?

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 merging the implementation does make sense. But merging the APIs is not.

Copy link
Contributor

Choose a reason for hiding this comment

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

i believe, history side start && start & signal APIs can be merged since it is not public.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about merge/reuse "start" but there is no good way to achieve it. "start" includes all complicate but not needed logic (like child, restart etc) for sigWithStart; and sigWithStart need start (just start) and signal in transaction.
I suggest keep sigWithStart separate from "start"

return nil, wh.error(createServiceBusyError(), scope)
}

if signalWithStartRequest.Domain == nil {

Choose a reason for hiding this comment

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

do you need to check if Domain == ""?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added. Will check and change all APIs in another request. #581

return nil, wh.error(&gen.BadRequestError{Message: "WorkflowId is not set on request."}, scope)
}

if signalWithStartRequest.SignalName == nil {

Choose a reason for hiding this comment

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

check SignalName == ""

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added.


// Start workflow and signal
request := getStartRequest(sRequest)
if request.ExecutionStartToCloseTimeoutSeconds == nil || *request.ExecutionStartToCloseTimeoutSeconds <= 0 {

Choose a reason for hiding this comment

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

maybe worth to reuse those parameter check with StartWorkflow()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good suggestion, changed.

@vancexu vancexu merged commit 2aca940 into master Mar 28, 2018
@vancexu vancexu deleted the sigwithstart branch March 28, 2018 22:32
wxing1292 pushed a commit that referenced this pull request Mar 29, 2018
* Add SignalWithStart

* rebase
@vancexu vancexu mentioned this pull request Mar 30, 2018
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.

4 participants