當前位置: 首頁>>代碼示例>>Golang>>正文


Golang JobServer.GetWorkUnits方法代碼示例

本文整理匯總了Golang中github.com/diffeo/go-coordinate/jobserver.JobServer.GetWorkUnits方法的典型用法代碼示例。如果您正苦於以下問題:Golang JobServer.GetWorkUnits方法的具體用法?Golang JobServer.GetWorkUnits怎麽用?Golang JobServer.GetWorkUnits使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/diffeo/go-coordinate/jobserver.JobServer的用法示例。


在下文中一共展示了JobServer.GetWorkUnits方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: listWorkUnits

// listWorkUnits calls GetWorkUnits (as the similarly-named Python
// function does) and validates that the response matches an expected
// set of work units.
func listWorkUnits(t *testing.T, j *jobserver.JobServer, workSpecName string, options map[string]interface{}, expected map[string]map[string]interface{}) {
	gwu, msg, err := j.GetWorkUnits(workSpecName, options)
	if !assert.NoError(t, err) {
		return
	}
	assert.Empty(t, msg)
	missing := make(map[string]struct{})
	for name := range expected {
		missing[name] = struct{}{}
	}
	for _, item := range gwu {
		if !assert.IsType(t, cborrpc.PythonTuple{}, item) {
			continue
		}
		tuple := item.(cborrpc.PythonTuple)
		if !assert.Len(t, tuple.Items, 2) {
			continue
		}
		if !assert.IsType(t, []byte{}, tuple.Items[0]) {
			continue
		}
		name := string(tuple.Items[0].([]byte))
		assert.IsType(t, map[string]interface{}{}, tuple.Items[1])
		if assert.Contains(t, expected, name, "unexpected work unit") {
			assert.Equal(t, expected[name], tuple.Items[1])
		}
		assert.Contains(t, missing, name, "duplicate work unit")
		delete(missing, name)
	}
}
開發者ID:diffeo,項目名稱:go-coordinate,代碼行數:33,代碼來源:python_test.go

示例2: getOneWorkUnit

// getOneWorkUnit calls GetWorkUnits for a single specific work unit,
// checks the results, and returns its data dictionary (or nil if absent).
func getOneWorkUnit(t *testing.T, j *jobserver.JobServer, workSpecName, workUnitKey string) map[string]interface{} {
	list, msg, err := j.GetWorkUnits(workSpecName, map[string]interface{}{"work_unit_keys": []interface{}{workUnitKey}})
	if !assert.NoError(t, err) {
		return nil
	}
	assert.Empty(t, msg)
	if !assert.Len(t, list, 1) {
		return nil
	}
	if !assert.IsType(t, cborrpc.PythonTuple{}, list[0]) {
		return nil
	}
	tuple := list[0].(cborrpc.PythonTuple)
	if !assert.Len(t, tuple.Items, 2) {
		return nil
	}
	assert.Equal(t, []byte(workUnitKey), tuple.Items[0])
	if assert.IsType(t, map[string]interface{}{}, tuple.Items[1]) {
		return tuple.Items[1].(map[string]interface{})
	}
	return nil
}
開發者ID:diffeo,項目名稱:go-coordinate,代碼行數:24,代碼來源:python_test.go


注:本文中的github.com/diffeo/go-coordinate/jobserver.JobServer.GetWorkUnits方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。