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

Golang monsterqueue.Job类代码示例

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

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



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

示例1: Run

func (t runBs) Run(job monsterqueue.Job) {
	params := job.Parameters()
	dockerEndpoint := params["endpoint"].(string)
	machineID := params["machine"].(string)
	err := t.waitDocker(dockerEndpoint)
	if err != nil {
		job.Error(err)
		return
	}
	err = t.createBsContainer(dockerEndpoint)
	if err != nil {
		job.Error(err)
		t.destroyMachine(machineID)
		return
	}
	rawMetadata := params["metadata"].(monsterqueue.JobParams)
	metadata := make(map[string]string, len(rawMetadata))
	for key, value := range rawMetadata {
		metadata[key] = value.(string)
	}
	_, err = mainDockerProvisioner.getCluster().Register(dockerEndpoint, metadata)
	if err != nil {
		job.Error(err)
		t.destroyMachine(machineID)
		return
	}
	job.Success(nil)
}
开发者ID:RichardKnop,项目名称:tsuru,代码行数:28,代码来源:queue_task.go


示例2: Run

func (t *runBs) Run(job monsterqueue.Job) {
	params := job.Parameters()
	dockerEndpoint := params["endpoint"].(string)
	node := cluster.Node{Address: dockerEndpoint}
	err := t.waitDocker(dockerEndpoint)
	if err != nil {
		job.Error(err)
		return
	}
	node.CreationStatus = cluster.NodeCreationStatusCreated
	rawMetadata := params["metadata"].(monsterqueue.JobParams)
	metadata := make(map[string]string, len(rawMetadata))
	for key, value := range rawMetadata {
		metadata[key] = value.(string)
	}
	err = createContainer(dockerEndpoint, metadata["pool"], t.provisioner, true)
	if err != nil {
		t.provisioner.Cluster().UpdateNode(node)
		job.Error(err)
		return
	}
	node.Metadata = map[string]string{"LastSuccess": time.Now().Format(time.RFC3339)}
	_, err = t.provisioner.Cluster().UpdateNode(node)
	if err != nil {
		job.Error(err)
		return
	}
	job.Success(nil)
}
开发者ID:nicolas2bonfils,项目名称:tsuru,代码行数:29,代码来源:queue.go


示例3: Run

func (t *runBs) Run(job monsterqueue.Job) {
	params := job.Parameters()
	dockerEndpoint := params["endpoint"].(string)
	machineID := params["machine"].(string)
	node := cluster.Node{Address: dockerEndpoint}
	err := t.waitDocker(dockerEndpoint)
	if err != nil {
		job.Error(err)
		t.destroyMachine(machineID)
		return
	}
	rawMetadata := params["metadata"].(monsterqueue.JobParams)
	metadata := make(map[string]string, len(rawMetadata))
	for key, value := range rawMetadata {
		metadata[key] = value.(string)
	}
	err = CreateContainer(dockerEndpoint, metadata["pool"], t.provisioner, true)
	if err != nil {
		node.CreationStatus = cluster.NodeCreationStatusError
		node.Metadata = map[string]string{"creationError": err.Error()}
		t.provisioner.Cluster().UpdateNode(node)
		job.Error(err)
		t.destroyMachine(machineID)
		return
	}
	node.CreationStatus = cluster.NodeCreationStatusCreated
	_, err = t.provisioner.Cluster().UpdateNode(node)
	if err != nil {
		job.Error(err)
		t.destroyMachine(machineID)
		return
	}
	job.Success(nil)
}
开发者ID:4eek,项目名称:tsuru,代码行数:34,代码来源:queue.go


示例4: AddNode

func (p *dockerProvisioner) AddNode(opts provision.AddNodeOptions) error {
	node := cluster.Node{
		Address:        opts.Address,
		Metadata:       opts.Metadata,
		CreationStatus: cluster.NodeCreationStatusPending,
		CaCert:         opts.CaCert,
		ClientCert:     opts.ClientCert,
		ClientKey:      opts.ClientKey,
	}
	if len(opts.CaCert) == 0 && len(p.caCert) > 0 {
		node.CaCert = p.caCert
		node.ClientCert = p.clientCert
		node.ClientKey = p.clientKey
	}
	err := p.Cluster().Register(node)
	if err != nil {
		return err
	}
	q, err := queue.Queue()
	if err != nil {
		return err
	}
	jobParams := monsterqueue.JobParams{"endpoint": opts.Address, "metadata": opts.Metadata}
	var job monsterqueue.Job
	if opts.WaitTO != 0 {
		job, err = q.EnqueueWait(internalNodeContainer.QueueTaskName, jobParams, opts.WaitTO)
	} else {
		_, err = q.Enqueue(internalNodeContainer.QueueTaskName, jobParams)
	}
	if err == nil && job != nil {
		_, err = job.Result()
	}
	return err
}
开发者ID:tsuru,项目名称:tsuru,代码行数:34,代码来源:provisioner.go


示例5: addNode

func (a *autoScaleConfig) addNode(event *autoScaleEvent, modelNodes []*cluster.Node) (*cluster.Node, error) {
	metadata, err := chooseMetadataFromNodes(modelNodes)
	if err != nil {
		return nil, err
	}
	_, hasIaas := metadata["iaas"]
	if !hasIaas {
		return nil, fmt.Errorf("no IaaS information in nodes metadata: %#v", metadata)
	}
	machine, err := iaas.CreateMachineForIaaS(metadata["iaas"], metadata)
	if err != nil {
		return nil, fmt.Errorf("unable to create machine: %s", err.Error())
	}
	newAddr := machine.FormatNodeAddress()
	event.logMsg("new machine created: %s - Waiting for docker to start...", newAddr)
	createdNode := cluster.Node{
		Address:        newAddr,
		Metadata:       metadata,
		CreationStatus: cluster.NodeCreationStatusPending,
	}
	err = a.provisioner.Cluster().Register(createdNode)
	if err != nil {
		machine.Destroy()
		return nil, fmt.Errorf("error registering new node %s: %s", newAddr, err.Error())
	}
	q, err := queue.Queue()
	if err == nil {
		jobParams := monsterqueue.JobParams{
			"endpoint": createdNode.Address,
			"machine":  machine.Id,
			"metadata": createdNode.Metadata,
		}
		var job monsterqueue.Job
		job, err = q.EnqueueWait(bs.QueueTaskName, jobParams, a.WaitTimeNewMachine)
		if err == nil {
			_, err = job.Result()
		}
	}
	if err != nil {
		machine.Destroy()
		a.provisioner.Cluster().Unregister(newAddr)
		return nil, fmt.Errorf("error running bs task: %s", err)
	}
	event.logMsg("new machine created: %s - started!", newAddr)
	return &createdNode, nil
}
开发者ID:nicolas2bonfils,项目名称:tsuru,代码行数:46,代码来源:auto_scale.go


示例6: Run

func (t *routesRebuildTask) Run(job monsterqueue.Job) {
	params := job.Parameters()
	appName, ok := params["appName"].(string)
	if !ok {
		job.Error(errors.New("invalid parameters, expected appName"))
	}
	for !runRoutesRebuildOnce(appName, true) {
		time.Sleep(routesRebuildRetryTime)
	}
	job.Success(nil)
}
开发者ID:zhenruyan,项目名称:tsuru,代码行数:11,代码来源:task.go


示例7: Run

func (t *machineCreate) Run(job monsterqueue.Job) {
	params := job.Parameters()
	jobId := params["jobId"].(string)
	vmId := params["vmId"].(string)
	projectId := params["projectId"].(string)
	ip, err := t.iaas.waitVMIsCreated(jobId, vmId, projectId)
	if err != nil {
		_, qErr := job.Queue().Enqueue(t.iaas.taskName(machineDeleteTaskName), monsterqueue.JobParams{
			"vmId":      vmId,
			"projectId": projectId,
		})
		if qErr != nil {
			job.Error(fmt.Errorf("error trying to enqueue deletion: %s caused by: %s", qErr, err))
			return
		}
		job.Error(err)
		return
	}
	if tags, ok := params["tags"]; ok {
		var cloudTags []*cloudstackTag
		tagList := strings.Split(tags.(string), ",")
		cloudTags = make([]*cloudstackTag, 0, len(tagList))
		for _, tag := range tagList {
			if strings.Contains(tag, ":") {
				parts := strings.SplitN(tag, ":", 2)
				cloudTags = append(cloudTags, &cloudstackTag{
					Key:   string(parts[0]),
					Value: string(parts[1]),
				})
			}
		}
		if len(cloudTags) > 0 {
			param := make(map[string]string)
			param["resourceids"] = vmId
			param["resourcetype"] = "UserVm"
			for index, tag := range cloudTags {
				param["tags["+strconv.Itoa(index+1)+"].key"] = tag.Key
				param["tags["+strconv.Itoa(index+1)+"].value"] = tag.Value
			}
			param["projectId"] = projectId
			var result CreateTagsResponse
			err = t.iaas.do("createTags", param, &result)
			if err != nil {
				job.Error(err)
				return
			}
		}
	}
	notified, _ := job.Success(ip)
	if !notified {
		_, err = job.Queue().Enqueue(t.iaas.taskName(machineDeleteTaskName), monsterqueue.JobParams{
			"vmId":      vmId,
			"projectId": projectId,
		})
		if err != nil {
			log.Errorf("could not enqueue delete unnotified vm: %s", err)
			return
		}
	}
}
开发者ID:zhenruyan,项目名称:tsuru,代码行数:60,代码来源:task.go


示例8: Run

func (t *machineCreate) Run(job monsterqueue.Job) {
	params := job.Parameters()
	jobId := params["jobId"].(string)
	vmId := params["vmId"].(string)
	projectId := params["projectId"].(string)
	ip, err := t.iaas.waitVMIsCreated(jobId, vmId, projectId)
	if err != nil {
		_, qErr := job.Queue().Enqueue(t.iaas.taskName(machineDeleteTaskName), monsterqueue.JobParams{
			"vmId":      vmId,
			"projectId": projectId,
		})
		if qErr != nil {
			job.Error(fmt.Errorf("error trying to enqueue deletion: %s caused by: %s", qErr, err))
			return
		}
		job.Error(err)
		return
	}
	notified, _ := job.Success(ip)
	if !notified {
		_, err = job.Queue().Enqueue(t.iaas.taskName(machineDeleteTaskName), monsterqueue.JobParams{
			"vmId":      vmId,
			"projectId": projectId,
		})
		if err != nil {
			log.Errorf("could not enqueue delete unnotified vm: %s", err)
			return
		}
	}
}
开发者ID:RichardKnop,项目名称:tsuru,代码行数:30,代码来源:task.go


示例9: Run

func (t *ec2WaitTask) Run(job monsterqueue.Job) {
	params := job.Parameters()
	regionOrEndpoint := getRegionOrEndpoint(map[string]string{
		"region":   params["region"].(string),
		"endpoint": params["endpoint"].(string),
	}, true)
	machineId := params["machineId"].(string)
	var timeout int
	switch val := params["timeout"].(type) {
	case int:
		timeout = val
	case float64:
		timeout = int(val)
	}
	networkIdx := -1
	if idx, ok := params["networkIndex"]; ok {
		switch val := idx.(type) {
		case int:
			networkIdx = val
		case float64:
			networkIdx = int(val)
		}
	}
	ec2Inst, err := t.iaas.createEC2Handler(regionOrEndpoint)
	if err != nil {
		job.Error(err)
		return
	}
	var dnsName string
	var notifiedSuccess bool
	t0 := time.Now()
	for {
		log.Debugf("ec2: waiting for dnsname for instance %s", machineId)
		input := ec2.DescribeInstancesInput{
			InstanceIds: []*string{aws.String(machineId)},
		}
		resp, err := ec2Inst.DescribeInstances(&input)
		if err != nil {
			job.Error(err)
			break
		}
		if len(resp.Reservations) == 0 || len(resp.Reservations[0].Instances) == 0 {
			job.Error(err)
			break
		}
		instance := resp.Reservations[0].Instances[0]
		if networkIdx < 0 {
			dnsName = aws.StringValue(instance.PublicDnsName)
		} else {
			if len(instance.NetworkInterfaces) < networkIdx {
				job.Error(errors.New("invalid network-index. "))
				break
			}
			dnsName = aws.StringValue(instance.NetworkInterfaces[networkIdx].PrivateDnsName)
		}
		if dnsName != "" {
			notifiedSuccess, _ = job.Success(dnsName)
			break
		}
		if time.Now().Sub(t0) > time.Duration(2*timeout)*time.Second {
			job.Error(errors.New("hard timeout"))
			break
		}
		time.Sleep(500 * time.Millisecond)
	}
	if !notifiedSuccess {
		input := ec2.TerminateInstancesInput{
			InstanceIds: []*string{aws.String(machineId)},
		}
		ec2Inst.TerminateInstances(&input)
	}
}
开发者ID:pedrosnk,项目名称:tsuru,代码行数:72,代码来源:task.go


示例10: Run

func (t *testTask) Run(j monsterqueue.Job) {
	t.callCount++
	j.Success("result")
}
开发者ID:zhenruyan,项目名称:tsuru,代码行数:4,代码来源:queue_test.go


示例11: Run

func (t *runBs) Run(job monsterqueue.Job) {
	params := job.Parameters()
	dockerEndpoint := params["endpoint"].(string)
	err := t.waitDocker(dockerEndpoint)
	if err != nil {
		job.Error(err)
		return
	}
	node, err := t.provisioner.Cluster().GetNode(dockerEndpoint)
	if err != nil {
		job.Error(err)
		return
	}
	node.CreationStatus = cluster.NodeCreationStatusCreated
	err = RecreateContainers(t.provisioner, nil, node)
	if err != nil {
		t.provisioner.Cluster().UpdateNode(node)
		job.Error(err)
		return
	}
	node.Metadata["LastSuccess"] = time.Now().Format(time.RFC3339)
	_, err = t.provisioner.Cluster().UpdateNode(node)
	if err != nil {
		job.Error(err)
		return
	}
	job.Success(nil)
}
开发者ID:pedrosnk,项目名称:tsuru,代码行数:28,代码来源:queue.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang action.NewPipeline函数代码示例发布时间:2022-05-28
下一篇:
Golang gnuflag.FlagSet类代码示例发布时间: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