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


Golang Namespace.SetWorkSpec方法代码示例

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


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

示例1: createWorkSpecs

func createWorkSpecs(namespace coordinate.Namespace) error {
	var err error
	_, err = namespace.SetWorkSpec(map[string]interface{}{
		"name":       "generator",
		"runtime":    "go",
		"task":       "generator",
		"continuous": true,
		"interval":   5,
		"then":       "runner",
	})
	if err != nil {
		return err
	}

	_, err = namespace.SetWorkSpec(map[string]interface{}{
		"name":        "runner",
		"runtime":     "go",
		"task":        "runner",
		"max_getwork": 10,
	})
	if err != nil {
		return err
	}

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

示例2: WorkSpec

// WorkSpec creates a work spec in the named namespace; if it fails,
// fail the test.
func (a *CacheAssertions) WorkSpec(ns coordinate.Namespace, name string) coordinate.WorkSpec {
	workSpec, err := ns.SetWorkSpec(map[string]interface{}{
		"name": name,
	})
	if !a.NoError(err, "error creating work spec") {
		a.FailNow("cannot create work spec")
	}
	return workSpec
}
开发者ID:diffeo,项目名称:go-coordinate,代码行数:11,代码来源:cache_test.go

示例3: TestMetaContinuous

// TestMetaContinuous specifically checks that you cannot enable the
// "continuous" flag on non-continuous work specs.
func TestMetaContinuous(t *testing.T) {
	var (
		err       error
		namespace coordinate.Namespace
		spec      coordinate.WorkSpec
		meta      coordinate.WorkSpecMeta
	)

	namespace, err = Coordinate.Namespace("TestMetaContinuous")
	if !assert.NoError(t, err) {
		return
	}
	defer namespace.Destroy()

	spec, err = namespace.SetWorkSpec(map[string]interface{}{
		"name":   "spec",
		"min_gb": 1,
	})
	if !assert.NoError(t, err) {
		return
	}

	meta, err = spec.Meta(false)
	if assert.NoError(t, err) {
		assert.False(t, meta.Continuous)
		assert.False(t, meta.CanBeContinuous)
	}

	meta.Continuous = true
	err = spec.SetMeta(meta)
	assert.NoError(t, err)

	meta, err = spec.Meta(false)
	if assert.NoError(t, err) {
		// Cannot set the "continuous" flag
		assert.False(t, meta.Continuous)
		assert.False(t, meta.CanBeContinuous)
	}
}
开发者ID:diffeo,项目名称:go-coordinate,代码行数:41,代码来源:work_spec.go

示例4: TestSetMeta

// TestSetMeta tests the basic SetMeta() call and a couple of its
// documented oddities.
func TestSetMeta(t *testing.T) {
	var (
		err       error
		namespace coordinate.Namespace
		spec      coordinate.WorkSpec
		meta      coordinate.WorkSpecMeta
	)

	namespace, err = Coordinate.Namespace("TestSetMeta")
	if !assert.NoError(t, err) {
		return
	}
	defer namespace.Destroy()

	spec, err = namespace.SetWorkSpec(map[string]interface{}{
		"name":       "spec",
		"min_gb":     1,
		"continuous": true,
	})
	if !assert.NoError(t, err) {
		return
	}

	meta, err = spec.Meta(false)
	if assert.NoError(t, err) {
		assert.Equal(t, 0, meta.Priority)
		assert.Equal(t, 20, meta.Weight)
		assert.False(t, meta.Paused)
		assert.True(t, meta.Continuous)
		assert.True(t, meta.CanBeContinuous)
		assert.Zero(t, meta.Interval)
		assert.WithinDuration(t, time.Time{}, meta.NextContinuous, 1*time.Microsecond)
		assert.Equal(t, 0, meta.MaxRunning)
		assert.Equal(t, 0, meta.MaxAttemptsReturned)
		assert.Equal(t, "", meta.NextWorkSpecName)
		assert.Equal(t, 0, meta.AvailableCount)
		assert.Equal(t, 0, meta.PendingCount)
		assert.Equal(t, "", meta.Runtime)
	}

	err = spec.SetMeta(coordinate.WorkSpecMeta{
		Priority:            10,
		Weight:              100,
		Paused:              true,
		Continuous:          false,
		CanBeContinuous:     false,
		Interval:            time.Duration(60) * time.Second,
		MaxRunning:          10,
		MaxAttemptsReturned: 1,
		NextWorkSpecName:    "then",
		AvailableCount:      100,
		PendingCount:        50,
		Runtime:             "go",
	})
	assert.NoError(t, err)

	meta, err = spec.Meta(false)
	if assert.NoError(t, err) {
		assert.Equal(t, 10, meta.Priority)
		assert.Equal(t, 100, meta.Weight)
		assert.True(t, meta.Paused)
		assert.False(t, meta.Continuous)
		// Cannot clear "can be continuous" flag
		assert.True(t, meta.CanBeContinuous)
		assert.Equal(t, 60*time.Second, meta.Interval)
		assert.WithinDuration(t, time.Time{}, meta.NextContinuous, 1*time.Microsecond)
		assert.Equal(t, 10, meta.MaxRunning)
		assert.Equal(t, 1, meta.MaxAttemptsReturned)
		// Cannot change following work spec
		assert.Equal(t, "", meta.NextWorkSpecName)
		// Cannot set the counts
		assert.Equal(t, 0, meta.AvailableCount)
		assert.Equal(t, 0, meta.PendingCount)
		// Cannot change the language runtime
		assert.Equal(t, "", meta.Runtime)
	}
}
开发者ID:diffeo,项目名称:go-coordinate,代码行数:79,代码来源:work_spec.go


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