本文整理汇总了Golang中github.com/diffeo/go-coordinate/coordinate.Namespace类的典型用法代码示例。如果您正苦于以下问题:Golang Namespace类的具体用法?Golang Namespace怎么用?Golang Namespace使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Namespace类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: fillWorkSpecShort
func (api *restAPI) fillWorkSpecShort(namespace coordinate.Namespace, name string, short *restdata.WorkSpecShort) error {
short.Name = name
return buildURLs(api.Router,
"namespace", namespace.Name(),
"spec", name,
).URL(&short.URL, "workSpec").Error
}
开发者ID:diffeo,项目名称:go-coordinate,代码行数:7,代码来源:work_spec.go
示例3: 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
示例4: 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
示例5: createWorker
// createWorker creates a worker with a random name. If there is a
// failure creating the worker, panics.
func createWorker(namespace coordinate.Namespace) coordinate.Worker {
// Construct a random worker name:
workerName := strings.Map(func(rune) rune {
return rune('A' + rand.Intn(26))
}, "12345678")
worker, err := namespace.Worker(workerName)
if err != nil {
panic(err)
}
return worker
}
开发者ID:diffeo,项目名称:go-coordinate,代码行数:13,代码来源:performance.go
示例6: attemptURLBuilder
func (api *restAPI) attemptURLBuilder(namespace coordinate.Namespace, attempt coordinate.Attempt, startTime time.Time, err error) *urlBuilder {
unit := attempt.WorkUnit()
spec := unit.WorkSpec()
worker := attempt.Worker()
if err == nil {
return buildURLs(api.Router,
"namespace", namespace.Name(),
"spec", spec.Name(),
"unit", unit.Name(),
"worker", worker.Name(),
"start", startTime.Format(time.RFC3339),
)
}
return &urlBuilder{Error: err}
}
开发者ID:diffeo,项目名称:go-coordinate,代码行数:15,代码来源:attempt.go
示例7: 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
示例8: fillWorkUnit
func (api *restAPI) fillWorkUnit(namespace coordinate.Namespace, spec coordinate.WorkSpec, unit coordinate.WorkUnit, repr *restdata.WorkUnit) error {
err := api.fillWorkUnitShort(namespace, spec, unit.Name(), &repr.WorkUnitShort)
if err == nil {
repr.Data, err = unit.Data()
}
if err == nil {
var meta coordinate.WorkUnitMeta
meta, err = unit.Meta()
repr.Meta = &meta
}
if err == nil {
repr.Status, err = unit.Status()
}
if err == nil {
err = buildURLs(api.Router,
"namespace", namespace.Name(),
"spec", spec.Name(),
"unit", unit.Name(),
).
URL(&repr.WorkSpecURL, "workSpec").
URL(&repr.AttemptsURL, "workUnitAttempts").
Error
}
if err == nil {
var attempt coordinate.Attempt
attempt, err = unit.ActiveAttempt()
if err == nil && attempt != nil {
// This is cheating, a little, but it's probably
// the easiest way to reuse this code
var short restdata.AttemptShort
err = api.fillAttemptShort(namespace, attempt, &short)
if err == nil {
repr.ActiveAttemptURL = short.URL
}
}
}
return err
}
开发者ID:diffeo,项目名称:go-coordinate,代码行数:38,代码来源:work_unit.go
示例9: fillWorkSpec
func (api *restAPI) fillWorkSpec(namespace coordinate.Namespace, name string, repr *restdata.WorkSpec) error {
err := api.fillWorkSpecShort(namespace, name, &repr.WorkSpecShort)
if err == nil {
err = buildURLs(api.Router,
"namespace", namespace.Name(),
"spec", name).
URL(&repr.WorkUnitsURL, "workUnits").
Template(&repr.WorkUnitURL, "workUnit", "unit").
URL(&repr.MetaURL, "workSpecMeta").
URL(&repr.WorkUnitCountsURL, "workSpecCounts").
URL(&repr.WorkUnitChangeURL, "workSpecChange").
URL(&repr.WorkUnitAdjustURL, "workSpecAdjust").
Error
}
if err == nil {
repr.MetaURL += "{?counts}"
qs := "{?name*,status*,previous,limit}"
repr.WorkUnitQueryURL = repr.WorkUnitsURL + qs
repr.WorkUnitChangeURL += qs
repr.WorkUnitAdjustURL += qs
}
return err
}
开发者ID:diffeo,项目名称:go-coordinate,代码行数:23,代码来源:work_spec.go
示例10: fillNamespaceShort
func (api *restAPI) fillNamespaceShort(namespace coordinate.Namespace, summary *restdata.NamespaceShort) error {
summary.Name = namespace.Name()
return buildURLs(api.Router, "namespace", summary.Name).
URL(&summary.URL, "namespace").
Error
}
开发者ID:diffeo,项目名称:go-coordinate,代码行数:6,代码来源:namespace.go
示例11: 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
示例12: 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.Namespace类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论