本文整理汇总了Golang中github.com/aws/aws-sdk-go/service/swf.PollForDecisionTaskOutput类的典型用法代码示例。如果您正苦于以下问题:Golang PollForDecisionTaskOutput类的具体用法?Golang PollForDecisionTaskOutput怎么用?Golang PollForDecisionTaskOutput使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PollForDecisionTaskOutput类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Poll
// Poll polls the task list for a task. If there is no task available, nil is
// returned. If an error is encountered, no task is returned.
func (p *DecisionTaskPoller) Poll(taskReady func(*swf.PollForDecisionTaskOutput) bool) (*swf.PollForDecisionTaskOutput, error) {
var resp *swf.PollForDecisionTaskOutput
eachPage := func(out *swf.PollForDecisionTaskOutput, lastPage bool) bool {
Log.Println("component=DecisionTaskPoller at=decision-task-page")
if resp == nil {
resp = out
} else {
resp.Events = append(resp.Events, out.Events...)
}
shouldContinue := !(lastPage || taskReady(resp)) //stop if last page or task ready
return shouldContinue
}
err := p.client.PollForDecisionTaskPages(&swf.PollForDecisionTaskInput{
Domain: aws.String(p.Domain),
Identity: aws.String(p.Identity),
ReverseOrder: aws.Bool(true),
TaskList: &swf.TaskList{Name: aws.String(p.TaskList)},
}, eachPage)
if err != nil {
Log.Printf("component=DecisionTaskPoller at=error error=%s", err.Error())
return nil, errors.Trace(err)
}
if resp != nil && resp.TaskToken != nil {
Log.Printf("component=DecisionTaskPoller at=decision-task-received workflow=%s", LS(resp.WorkflowType.Name))
p.logTaskLatency(resp)
return resp, nil
}
Log.Println("component=DecisionTaskPoller at=decision-task-empty-response")
return nil, nil
}
开发者ID:fivebats,项目名称:swfsm,代码行数:35,代码来源:poller.go
示例2: 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:fivebats,项目名称:swfsm,代码行数:51,代码来源:fsm.go
示例3: 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
示例4: Poll
// Poll polls the task list for a task. If there is no task available, nil is
// returned. If an error is encountered, no task is returned.
func (p *DecisionTaskPoller) Poll(taskReady func(*swf.PollForDecisionTaskOutput) bool) (*swf.PollForDecisionTaskOutput, error) {
var (
resp *swf.PollForDecisionTaskOutput
page int
pollId = uuid.New()
)
eachPage := func(out *swf.PollForDecisionTaskOutput, _ bool) bool {
page++
var (
firstEventId *int64
lastEventId *int64
workflowId string
)
if len(out.Events) > 0 {
firstEventId = out.Events[0].EventId
lastEventId = out.Events[len(out.Events)-1].EventId
}
if out.WorkflowExecution != nil {
workflowId = LS(out.WorkflowExecution.WorkflowId)
} else {
workflowId = "no-workflow-execution"
}
Log.Printf("component=DecisionTaskPoller at=decision-task-page poll-id=%q task-list=%q workflow=%q page=%d "+
"PreviousStartedEventId=%s StartedEventId=%s NumEvents=%d FirstEventId=%s LastEventId=%s",
pollId, p.TaskList, workflowId, page,
LL(out.PreviousStartedEventId), LL(out.StartedEventId), len(out.Events), LL(firstEventId), LL(lastEventId))
if resp == nil {
resp = out
} else {
resp.Events = append(resp.Events, out.Events...)
}
return !taskReady(resp)
}
err := p.client.PollForDecisionTaskPages(&swf.PollForDecisionTaskInput{
Domain: aws.String(p.Domain),
Identity: aws.String(p.Identity),
ReverseOrder: aws.Bool(true),
TaskList: &swf.TaskList{Name: aws.String(p.TaskList)},
}, eachPage)
if err != nil {
Log.Printf("component=DecisionTaskPoller poll-id=%q task-list=%q at=error error=%s",
pollId, p.TaskList, err.Error())
return nil, errors.Trace(err)
}
if resp != nil && resp.TaskToken != nil {
Log.Printf("component=DecisionTaskPoller poll-id=%q at=decision-task-received task-list=%q workflow=%q",
pollId, p.TaskList, LS(resp.WorkflowExecution.WorkflowId))
p.logTaskLatency(resp)
return resp, nil
}
Log.Printf("component=DecisionTaskPoller at=decision-task-empty-response poll-id=%q task-list=%q", pollId, p.TaskList)
return nil, nil
}
开发者ID:chadqueen,项目名称:swfsm,代码行数:64,代码来源:poller.go
注:本文中的github.com/aws/aws-sdk-go/service/swf.PollForDecisionTaskOutput类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论