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


Golang JobServer.GetWork方法代码示例

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


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

示例1: getOneWork

func getOneWork(t *testing.T, j *jobserver.JobServer) (ok bool, workSpecName, workUnitKey string, workUnitData map[string]interface{}) {
	anything, msg, err := j.GetWork("test", map[string]interface{}{"available_gb": 1})
	if !assert.NoError(t, err) {
		return
	}
	assert.Empty(t, msg)
	// Since we didn't request multiple work units we should always
	// get at most one, but maybe none
	if assert.NotNil(t, anything) &&
		assert.IsType(t, cborrpc.PythonTuple{}, anything) {
		tuple := anything.(cborrpc.PythonTuple)
		if assert.Len(t, tuple.Items, 3) {
			// "no work unit" gets returned as tuple (nil,
			// nil, nil)
			if tuple.Items[0] != nil &&
				assert.IsType(t, "", tuple.Items[0]) &&
				assert.IsType(t, []byte{}, tuple.Items[1]) &&
				assert.IsType(t, map[string]interface{}{}, tuple.Items[2]) {
				ok = true
				workSpecName = tuple.Items[0].(string)
				bWorkUnitKey := tuple.Items[1].([]byte)
				workUnitKey = string(bWorkUnitKey)
				workUnitData = tuple.Items[2].(map[string]interface{})
			}
		}
	}
	return
}
开发者ID:diffeo,项目名称:go-coordinate,代码行数:28,代码来源:python_test.go

示例2: getSpecificWork

// getSpecificWork calls GetWork expecting a specific work unit to
// come back, and returns its data dictionary.
func getSpecificWork(t *testing.T, j *jobserver.JobServer, workSpecName, workUnitKey string) map[string]interface{} {
	anything, msg, err := j.GetWork("test", map[string]interface{}{"available_gb": 1})
	if !assert.NoError(t, err) {
		return nil
	}
	assert.Empty(t, msg)
	if assert.NotNil(t, anything) && assert.IsType(t, cborrpc.PythonTuple{}, anything) {
		tuple := anything.(cborrpc.PythonTuple)
		if assert.Len(t, tuple.Items, 3) && assert.NotNil(t, tuple.Items[0]) {
			assert.Equal(t, workSpecName, tuple.Items[0])
			assert.Equal(t, []byte(workUnitKey), tuple.Items[1])
			if assert.IsType(t, tuple.Items[2], map[string]interface{}{}) {
				return tuple.Items[2].(map[string]interface{})
			}
		}
	}
	return nil
}
开发者ID:diffeo,项目名称:go-coordinate,代码行数:20,代码来源:python_test.go


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