當前位置: 首頁>>代碼示例>>Golang>>正文


Golang PollForDecisionTaskOutput.PreviousStartedEventID方法代碼示例

本文整理匯總了Golang中github.com/aws/aws-sdk-go/service/swf.PollForDecisionTaskOutput.PreviousStartedEventID方法的典型用法代碼示例。如果您正苦於以下問題:Golang PollForDecisionTaskOutput.PreviousStartedEventID方法的具體用法?Golang PollForDecisionTaskOutput.PreviousStartedEventID怎麽用?Golang PollForDecisionTaskOutput.PreviousStartedEventID使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/aws/aws-sdk-go/service/swf.PollForDecisionTaskOutput的用法示例。


在下文中一共展示了PollForDecisionTaskOutput.PreviousStartedEventID方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: ErrorStateTick

// ErrorStateTick is called when the DecisionTaskPoller receives a PollForDecisionTaskResponse in its polling loop
// that contains an error marker in its history.
func (f *FSM) ErrorStateTick(decisionTask *swf.PollForDecisionTaskOutput, error *SerializedErrorState, context *FSMContext, data interface{}) (*Outcome, error) {
	handler := f.errorHandlers[context.State]
	if handler == nil {
		handler = f.DecisionErrorHandler
	}
	handled, notHandled := handler(context, error.ErrorEvent, data, data, nil)
	if handled == nil {
		return nil, notHandled
	}

	//todo we are assuming all history events in the range
	//error.EarliestUnprocessedEventID to error.LatestUnprocessedEventID
	//are in the decisionTaks.History
	filteredDecisionTask := new(swf.PollForDecisionTaskOutput)
	s, e := f.systemSerializer.Serialize(decisionTask)
	if e != nil {
		return nil, e
	}
	e = f.systemSerializer.Deserialize(s, filteredDecisionTask)
	if e != nil {
		return nil, e
	}

	filtered := make([]*swf.HistoryEvent, 0)
	for _, h := range decisionTask.Events {
		if f.isErrorMarker(h) {
			continue
		}
		filtered = append(filtered, h)
	}
	filteredDecisionTask.Events = filtered
	filteredDecisionTask.StartedEventID = &error.LatestUnprocessedEventID
	filteredDecisionTask.PreviousStartedEventID = &error.EarliestUnprocessedEventID

	_, decisions, serializedState, err := f.Tick(filteredDecisionTask)
	if err != nil {
		data := f.zeroStateData()
		f.Deserialize(serializedState.StateData, data)

		return &Outcome{
			State:     serializedState.StateName,
			Decisions: decisions,
			Data:      data,
		}, nil

	}

	return nil, err
}
開發者ID:uberbrodt,項目名稱:swfsm,代碼行數:51,代碼來源:fsm.go

示例2: TestInterceptors

func TestInterceptors(t *testing.T) {
	calledAfter := false
	calledBefore := false
	calledBeforeCtx := false

	interceptor := &FuncInterceptor{
		BeforeTaskFn: func(decision *swf.PollForDecisionTaskOutput) {
			calledBefore = true
		},
		BeforeDecisionFn: func(decision *swf.PollForDecisionTaskOutput, ctx *FSMContext, outcome *Outcome) {
			outcome.Decisions = append(outcome.Decisions, ctx.CompleteWorkflowDecision(&TestData{}))
			outcome.Decisions = append(outcome.Decisions, ctx.CompleteWorkflowDecision(&TestData{}))
			calledBeforeCtx = true
		},
		AfterDecisionFn: func(decision *swf.PollForDecisionTaskOutput, ctx *FSMContext, outcome *Outcome) {
			if countCompletes(outcome.Decisions) != 2 {
				t.Fatal("not 2 completes in after")
			}
			outcome.Decisions = dedupeCompletes(outcome.Decisions)
			if countCompletes(outcome.Decisions) != 1 {
				t.Fatal("not 1 completes in after dedupe")
			}
			calledAfter = true
		},
	}

	fsm := &FSM{
		Name:                "test-fsm",
		DataType:            TestData{},
		DecisionInterceptor: interceptor,
		Serializer:          JSONStateSerializer{},
		systemSerializer:    JSONStateSerializer{},
	}

	fsm.AddInitialState(&FSMState{Name: "initial", Decider: func(ctx *FSMContext, e *swf.HistoryEvent, d interface{}) Outcome {
		return Outcome{State: "initial", Data: d, Decisions: []*swf.Decision{}}
	}})

	decisionTask := new(swf.PollForDecisionTaskOutput)
	decisionTask.WorkflowExecution = new(swf.WorkflowExecution)
	decisionTask.WorkflowType = &swf.WorkflowType{Name: S("test"), Version: S("1")}
	decisionTask.WorkflowExecution.RunID = S("run")
	decisionTask.WorkflowExecution.WorkflowID = S("wf")
	decisionTask.PreviousStartedEventID = I(5)
	decisionTask.StartedEventID = I(15)
	decisionTask.Events = []*swf.HistoryEvent{
		{
			EventID:   I(10),
			EventType: S("WorkflowExecutionStarted"),
			WorkflowExecutionStartedEventAttributes: &swf.WorkflowExecutionStartedEventAttributes{
				Input: StartFSMWorkflowInput(fsm, new(TestData)),
			},
		},
	}

	_, ds, _, _ := fsm.Tick(decisionTask)

	if calledBefore == false {
		t.Fatalf("before not called")
	}

	if calledBeforeCtx == false {
		t.Fatalf("before context not called")
	}

	if calledAfter == false {
		t.Fatalf("after not called")
	}

	if countCompletes(ds) != 1 {
		t.Fatalf("Deduping completes failed %v", ds)
	}
}
開發者ID:uberbrodt,項目名稱:swfsm,代碼行數:73,代碼來源:interceptors_test.go


注:本文中的github.com/aws/aws-sdk-go/service/swf.PollForDecisionTaskOutput.PreviousStartedEventID方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。