• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang migrator.WorkflowTypeMigrator类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/sclasen/swfsm/migrator.WorkflowTypeMigrator的典型用法代码示例。如果您正苦于以下问题:Golang WorkflowTypeMigrator类的具体用法?Golang WorkflowTypeMigrator怎么用?Golang WorkflowTypeMigrator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了WorkflowTypeMigrator类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: TestTypedActivityWorker

func TestTypedActivityWorker(t *testing.T) {
	if os.Getenv("AWS_ACCESS_KEY_ID") == "" || os.Getenv("AWS_SECRET_ACCESS_KEY") == "" {
		Log.Printf("WARNING: NO AWS CREDS SPECIFIED, SKIPPING MIGRATIONS TEST")
		return
	}

	config := &aws.Config{
		Credentials: credentials.NewEnvCredentials(),
		Region:      aws.String("us-east-1"),
	}

	client := swf.New(session.New(config))

	domain := "worker-test-domain"

	req := swf.RegisterDomainInput{
		Name:                                   aws.String(domain),
		Description:                            aws.String("test domain"),
		WorkflowExecutionRetentionPeriodInDays: aws.String("30"),
	}

	d := migrator.DomainMigrator{
		RegisteredDomains: []swf.RegisterDomainInput{req},
		Client:            client,
	}

	d.Migrate()

	workflow := "worker-test-workflow"
	version := "worker-test-workflow-version"

	wreq := swf.RegisterWorkflowTypeInput{
		Name:            &workflow,
		Description:     aws.String("test workflow migration"),
		Version:         &version,
		Domain:          aws.String(domain),
		DefaultTaskList: &swf.TaskList{Name: S("worker-fsm")},
	}

	w := migrator.WorkflowTypeMigrator{
		RegisteredWorkflowTypes: []swf.RegisterWorkflowTypeInput{wreq},
		Client:                  client,
	}

	w.Migrate()

	one := swf.RegisterActivityTypeInput{
		Name:        aws.String("one"),
		Description: aws.String("worker test activity 1"),
		Version:     aws.String("one"),
		Domain:      aws.String(domain),
	}

	two := swf.RegisterActivityTypeInput{
		Name:        aws.String("two"),
		Description: aws.String("worker test activity 2"),
		Version:     aws.String("two"),
		Domain:      aws.String(domain),
	}

	a := migrator.ActivityTypeMigrator{
		RegisteredActivityTypes: []swf.RegisterActivityTypeInput{one, two},
		Client:                  client,
	}

	a.Migrate()

	taskList := "aTaskListSharedBetweenTaskOneAndTwo"

	worker := &ActivityWorker{
		Domain:     domain,
		Serializer: fsm.JSONStateSerializer{},
		TaskList:   taskList,
		SWF:        client,
		Identity:   "test-activity-worker",
	}

	//This is where the actual worker config code is
	var activities Activities

	activities = MockActivities{}

	worker.AddHandler(NewActivityHandler("one", activities.Task1))

	worker.AddHandler(NewActivityHandler("two", activities.Task2))

	go worker.Start()
	//yep thats all the worker config code

	done := make(chan struct{})

	go NewWorkerFSM(client, done).Start()

	_, err := client.StartWorkflowExecution(&swf.StartWorkflowExecutionInput{
		Domain:       S(domain),
		WorkflowId:   S("worker-test"),
		WorkflowType: &swf.WorkflowType{Name: S(workflow), Version: S(version)},
		Input:        S("{}"),
		ExecutionStartToCloseTimeout: S("90"),
		TaskStartToCloseTimeout:      S("10"),
//.........这里部分代码省略.........
开发者ID:ryanwalls,项目名称:swfsm,代码行数:101,代码来源:worker_test.go


示例2: TestClient

func TestClient(t *testing.T) {
	if os.Getenv("AWS_ACCESS_KEY_ID") == "" || os.Getenv("AWS_SECRET_ACCESS_KEY") == "" {
		Log.Printf("WARNING: NO AWS CREDS SPECIFIED, SKIPPING MIGRATIONS TEST")
		return
	}

	config := &aws.Config{
		Credentials: credentials.NewEnvCredentials(),
		Region:      aws.String("us-east-1"),
	}
	client := swf.New(session.New(config))

	req := swf.RegisterDomainInput{
		Name:                                   aws.String("client-test"),
		Description:                            aws.String("test domain"),
		WorkflowExecutionRetentionPeriodInDays: aws.String("30"),
	}

	d := migrator.DomainMigrator{
		RegisteredDomains: []swf.RegisterDomainInput{req},
		Client:            client,
	}

	d.Migrate()

	wreq := swf.RegisterWorkflowTypeInput{
		Name:        aws.String("client-test"),
		Description: aws.String("test workflow migration"),
		Version:     aws.String("1"),
		Domain:      aws.String("client-test"),
	}

	w := migrator.WorkflowTypeMigrator{
		RegisteredWorkflowTypes: []swf.RegisterWorkflowTypeInput{wreq},
		Client:                  client,
	}

	w.Migrate()

	fsm := &FSM{
		Domain:           "client-test",
		Name:             "client-test",
		DataType:         TestData{},
		Serializer:       JSONStateSerializer{},
		SystemSerializer: JSONStateSerializer{},
		AllowPanics:      false,
	}

	fsm.AddInitialState(&FSMState{Name: "initial",
		Decider: func(ctx *FSMContext, h *swf.HistoryEvent, data interface{}) Outcome {
			if *h.EventType == swf.EventTypeWorkflowExecutionSignaled {
				d := data.(*TestData)
				d.States = append(d.States, *h.WorkflowExecutionSignaledEventAttributes.SignalName)
			}
			return ctx.Stay(data, ctx.EmptyDecisions())
		},
	})

	fsmClient := NewFSMClient(fsm, client)

	workflow := uuid.New()
	testData := uuid.New()
	startTemplate := swf.StartWorkflowExecutionInput{
		WorkflowType:                 &swf.WorkflowType{Name: aws.String("client-test"), Version: aws.String("1")},
		ExecutionStartToCloseTimeout: aws.String("120"),
		TaskStartToCloseTimeout:      aws.String("120"),
		ChildPolicy:                  aws.String("ABANDON"),
		TaskList:                     &swf.TaskList{Name: aws.String("task-list")},
	}
	_, err := fsmClient.Start(startTemplate, workflow, &TestData{States: []string{testData}})

	if err != nil {
		t.Fatal(err)
	}

	state, data, err := fsmClient.GetState(workflow)
	if err != nil {
		t.Fatal(err)
	}

	if data.(*TestData).States[0] != testData {
		t.Fatal(data)
	}

	if state != "initial" {
		t.Fatal("not in initial")
	}

	found := false
	err = fsmClient.WalkOpenWorkflowInfos(&swf.ListOpenWorkflowExecutionsInput{}, func(infos *swf.WorkflowExecutionInfos) error {
		for _, info := range infos.ExecutionInfos {
			if *info.Execution.WorkflowId == workflow {
				found = true
				return StopWalking()
			}
		}
		return nil
	})

	if err != nil {
//.........这里部分代码省略.........
开发者ID:ryanwalls,项目名称:swfsm,代码行数:101,代码来源:client_test.go



注:本文中的github.com/sclasen/swfsm/migrator.WorkflowTypeMigrator类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang sugar.S函数代码示例发布时间:2022-05-28
下一篇:
Golang migrator.DomainMigrator类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap