当前位置: 首页>>代码示例>>Golang>>正文


Golang Worker.Name方法代码示例

本文整理汇总了Golang中github.com/diffeo/go-coordinate/coordinate.Worker.Name方法的典型用法代码示例。如果您正苦于以下问题:Golang Worker.Name方法的具体用法?Golang Worker.Name怎么用?Golang Worker.Name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/diffeo/go-coordinate/coordinate.Worker的用法示例。


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

示例1: SetParent

func (w *worker) SetParent(parent coordinate.Worker) error {
	parentName := ""
	if parent != nil {
		parentName = parent.Name()
	}
	repr := restdata.Worker{Parent: &parentName}
	return w.Put(repr, nil)
}
开发者ID:diffeo,项目名称:go-coordinate,代码行数:8,代码来源:worker.go

示例2: wrapWorker

// wrapWorker returns a cache.worker object for a specific upstream
// Worker.
func (ns *namespace) wrapWorker(upstream coordinate.Worker) *worker {
	// This cannot fail: it can only fail if the embedded function
	// returns an error, and the embedded function never fails
	downstream, _ := ns.workers.Get(upstream.Name(), func(string) (named, error) {
		return newWorker(upstream, ns), nil
	})
	return downstream.(*worker)
}
开发者ID:diffeo,项目名称:go-coordinate,代码行数:10,代码来源:namespace.go

示例3: fillWorkerShort

func (api *restAPI) fillWorkerShort(namespace coordinate.Namespace, worker coordinate.Worker, short *restdata.WorkerShort) error {
	short.Name = worker.Name()
	return buildURLs(api.Router,
		"namespace", namespace.Name(),
		"worker", short.Name,
	).
		URL(&short.URL, "worker").
		Error
}
开发者ID:diffeo,项目名称:go-coordinate,代码行数:9,代码来源:worker.go

示例4: TestWorkerAncestry

// TestWorkerAncestry does basic tests on worker parents and children.
func TestWorkerAncestry(t *testing.T) {
	var (
		err                   error
		parent, child, worker coordinate.Worker
		kids                  []coordinate.Worker
	)

	sts := SimpleTestSetup{NamespaceName: "TestWorkerAncestry"}
	sts.SetUp(t)
	defer sts.TearDown(t)

	// start in the middle
	parent, err = sts.Namespace.Worker("parent")
	if !assert.NoError(t, err) {
		return
	}

	worker, err = parent.Parent()
	if assert.NoError(t, err) {
		assert.Nil(t, worker)
	}
	kids, err = parent.Children()
	if assert.NoError(t, err) {
		assert.Empty(t, kids)
	}

	// Create a child
	child, err = sts.Namespace.Worker("child")
	if !assert.NoError(t, err) {
		return
	}
	err = child.SetParent(parent)
	assert.NoError(t, err)

	// this should update the parent metadata
	worker, err = parent.Parent()
	if assert.NoError(t, err) {
		assert.Nil(t, worker)
	}
	kids, err = parent.Children()
	if assert.NoError(t, err) && assert.Len(t, kids, 1) {
		assert.Equal(t, "child", kids[0].Name())
	}

	// and also the child metadata
	worker, err = child.Parent()
	if assert.NoError(t, err) && assert.NotNil(t, worker) {
		assert.Equal(t, "parent", worker.Name())
	}
	kids, err = child.Children()
	if assert.NoError(t, err) {
		assert.Empty(t, kids)
	}
}
开发者ID:diffeo,项目名称:go-coordinate,代码行数:55,代码来源:worker.go

示例5: WorkerPut

func (api *restAPI) WorkerPut(ctx *context, in interface{}) (interface{}, error) {
	var err error

	repr, valid := in.(restdata.Worker)
	if !valid {
		return nil, errUnmarshal
	}

	// Did the parent change?
	if repr.Parent != nil {
		var oldParent, newParent coordinate.Worker
		oldParent, err = ctx.Worker.Parent()
		oldParentName := ""
		if err == nil && oldParent != nil {
			oldParentName = oldParent.Name()
		}
		if err == nil && *repr.Parent != oldParentName {
			if *repr.Parent != "" {
				newParent, err = ctx.Namespace.Worker(*repr.Parent)
			}
			if err == nil {
				err = ctx.Worker.SetParent(newParent)
			}
		}
	}

	// Do we need to deactivate ourselves?  Or update?
	var wasActive bool
	if err == nil {
		wasActive, err = ctx.Worker.Active()
	}
	if err == nil && repr.Active {
		// May as well update; checking everything else is
		// a little irritating
		err = ctx.Worker.Update(repr.Data, repr.LastUpdate, repr.Expiration, repr.Mode)
	} else if err == nil && wasActive {
		// was active, not active now (else we hit the previous block)
		err = ctx.Worker.Deactivate()
	}

	return nil, err
}
开发者ID:diffeo,项目名称:go-coordinate,代码行数:42,代码来源:worker.go

示例6: TestWorkerAdoption

// TestWorkerAdoption hands a child worker to a new parent.
func TestWorkerAdoption(t *testing.T) {
	var (
		err                                 error
		child, oldParent, newParent, worker coordinate.Worker
		kids                                []coordinate.Worker
	)

	sts := SimpleTestSetup{NamespaceName: "TestWorkerAdoption"}
	sts.SetUp(t)
	defer sts.TearDown(t)

	// Create the worker objects
	child, err = sts.Namespace.Worker("child")
	if !assert.NoError(t, err) {
		return
	}
	oldParent, err = sts.Namespace.Worker("old")
	if !assert.NoError(t, err) {
		return
	}
	newParent, err = sts.Namespace.Worker("new")
	if !assert.NoError(t, err) {
		return
	}

	// Set up the original ancestry
	err = child.SetParent(oldParent)
	assert.NoError(t, err)

	// Move it to the new parent
	err = child.SetParent(newParent)
	assert.NoError(t, err)

	// Checks
	worker, err = child.Parent()
	if assert.NoError(t, err) && assert.NotNil(t, worker) {
		assert.Equal(t, "new", worker.Name())
	}
	kids, err = child.Children()
	if assert.NoError(t, err) {
		assert.Empty(t, kids)
	}

	worker, err = oldParent.Parent()
	if assert.NoError(t, err) {
		assert.Nil(t, worker)
	}
	kids, err = oldParent.Children()
	if assert.NoError(t, err) {
		assert.Empty(t, kids)
	}

	worker, err = newParent.Parent()
	if assert.NoError(t, err) {
		assert.Nil(t, worker)
	}
	kids, err = newParent.Children()
	if assert.NoError(t, err) && assert.Len(t, kids, 1) {
		assert.Equal(t, "child", kids[0].Name())
	}
}
开发者ID:diffeo,项目名称:go-coordinate,代码行数:62,代码来源:worker.go

示例7: fillWorker

func (api *restAPI) fillWorker(namespace coordinate.Namespace, worker coordinate.Worker, result *restdata.Worker) error {
	err := api.fillWorkerShort(namespace, worker, &result.WorkerShort)
	if err == nil {
		err = buildURLs(api.Router,
			"namespace", namespace.Name(),
			"worker", worker.Name(),
		).
			URL(&result.RequestAttemptsURL, "workerRequestAttempts").
			URL(&result.MakeAttemptURL, "workerMakeAttempt").
			URL(&result.ActiveAttemptsURL, "workerActiveAttempts").
			URL(&result.AllAttemptsURL, "workerAllAttempts").
			URL(&result.ChildAttemptsURL, "workerChildAttempts").
			Error
	}
	var parent coordinate.Worker
	if err == nil {
		parent, err = worker.Parent()
	}
	if err == nil && parent != nil {
		parentName := parent.Name()
		result.Parent = &parentName
		err = buildURLs(api.Router,
			"namespace", namespace.Name(),
			"worker", parent.Name(),
		).
			URL(&result.ParentURL, "worker").
			Error
	}
	var children []coordinate.Worker
	if err == nil {
		children, err = worker.Children()
	}
	if err == nil {
		result.ChildURLs = make([]string, len(children))
		for i, child := range children {
			err = buildURLs(api.Router,
				"namespace", namespace.Name(),
				"worker", child.Name(),
			).
				URL(&result.ChildURLs[i], "worker").
				Error
			if err != nil {
				break
			}
		}
	}
	if err == nil {
		result.Active, err = worker.Active()
	}
	if err == nil {
		result.Mode, err = worker.Mode()
	}
	if err == nil {
		result.Data, err = worker.Data()
	}
	if err == nil {
		result.Expiration, err = worker.Expiration()
	}
	if err == nil {
		result.LastUpdate, err = worker.LastUpdate()
	}
	return err
}
开发者ID:diffeo,项目名称:go-coordinate,代码行数:63,代码来源:worker.go


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