本文整理匯總了Golang中github.com/MG-RAST/AWE/lib/core.Workunit.State方法的典型用法代碼示例。如果您正苦於以下問題:Golang Workunit.State方法的具體用法?Golang Workunit.State怎麽用?Golang Workunit.State使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/MG-RAST/AWE/lib/core.Workunit
的用法示例。
在下文中一共展示了Workunit.State方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ParseWorkunitArgs
//parse workunit, fetch input data, compose command arguments
func ParseWorkunitArgs(work *core.Workunit) (err error) {
args := []string{}
argstr := work.Cmd.Args
if argstr == "" {
return
}
argList := parse_arg_string(argstr)
for _, arg := range argList {
match, err := regexp.Match(`\$\{\w+\}`, []byte(arg))
if err == nil && match { //replace environment variable with its value
reg := regexp.MustCompile(`\$\{\w+\}`)
vabs := reg.FindAll([]byte(arg), -1)
parsedArg := arg
for _, vab := range vabs {
vb := bytes.TrimPrefix(vab, []byte("${"))
vb = bytes.TrimSuffix(vb, []byte("}"))
envvalue := os.Getenv(string(vb))
fmt.Printf("%s=%s\n", vb, envvalue)
parsedArg = strings.Replace(parsedArg, string(vab), envvalue, 1)
}
args = append(args, parsedArg)
continue
}
if strings.Contains(arg, "@") { //parse input/output to accessible local file
segs := strings.Split(arg, "@")
if len(segs) > 2 {
return errors.New("invalid format in command args, multiple @ within one arg")
}
inputname := segs[1]
if work.Inputs.Has(inputname) {
inputFilePath := path.Join(work.Path(), inputname)
parsedArg := fmt.Sprintf("%s%s", segs[0], inputFilePath)
args = append(args, parsedArg)
}
continue
}
//no @ or $, append directly
args = append(args, arg)
}
work.Cmd.ParsedArgs = args
work.State = core.WORK_STAT_PREPARED
return nil
}
示例2: ParseWorkunitArgs
//parse workunit, fetch input data, compose command arguments
func ParseWorkunitArgs(work *core.Workunit) (err error) {
args := []string{}
argstr := work.Cmd.Args
if argstr == "" {
return
}
workpath := work.Path()
if len(work.Cmd.Dockerimage) > 0 {
workpath = conf.DOCKER_WORK_DIR
}
// use better file name replacement technique
var virtual_cmd_script = []string{argstr}
replace_filepath_with_full_filepath(work.Inputs, workpath, virtual_cmd_script)
argstr = virtual_cmd_script[0]
argList := parse_arg_string(argstr)
for _, arg := range argList {
match, err := regexp.Match(`\$\{\w+\}`, []byte(arg))
if err == nil && match { //replace environment variable with its value
reg := regexp.MustCompile(`\$\{\w+\}`)
vabs := reg.FindAll([]byte(arg), -1)
parsedArg := arg
for _, vab := range vabs {
vb := bytes.TrimPrefix(vab, []byte("${"))
vb = bytes.TrimSuffix(vb, []byte("}"))
envvalue := os.Getenv(string(vb))
fmt.Printf("%s=%s\n", vb, envvalue)
parsedArg = strings.Replace(parsedArg, string(vab), envvalue, 1)
}
args = append(args, parsedArg)
continue
}
// this might be deprecated by replace_filepath_with_full_filepath
if strings.Contains(arg, "@") { //parse input/output to accessible local file
segs := strings.Split(arg, "@")
if len(segs) > 2 {
return errors.New("invalid format in command args, multiple @ within one arg")
}
inputname := segs[1]
for _, io := range work.Inputs {
if io.FileName == inputname {
inputFilePath := path.Join(workpath, inputname)
parsedArg := fmt.Sprintf("%s%s", segs[0], inputFilePath)
args = append(args, parsedArg)
}
}
continue
}
//no @ or $, append directly
args = append(args, arg)
}
work.Cmd.ParsedArgs = args
work.State = core.WORK_STAT_PREPARED
return nil
}