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


Golang Job.GetOrCreateFlow方法代碼示例

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


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

示例1: Init


//.........這裏部分代碼省略.........

	if p.path != "" {
		if _, err := os.Stat(p.path); os.IsNotExist(err) {
			return errors.New("File " + p.path + " does not exist.")
		}

		if path.Ext(p.path) == ".lua" {
			p.url = "tpl://" + p.path
			p.path = ""
		} else {
			if len(p.scriptArgs) != 0 {
				return errors.New("You cannot specify an key/value hash of arguments when executing an external process. Provide an array of arguments instead.")
			}
		}
	}

	if p.url != "" {
		if len(p.args) != 0 {
			return errors.New("You cannot specify an array of arguments when executing a template. Provide a key/value hash instead.")
		}

		if strings.HasPrefix(p.url, "tpl://") {
			URL, err := url.Parse(p.url)

			if err != nil {
				return err
			}

			p.templateFile = URL.Host + URL.Path

			if _, err := os.Stat(p.templateFile); os.IsNotExist(err) {
				return errors.New("Template " + p.templateFile + " does not exist.")
			}
		}
	}

	template, templateOK := c["template"]
	variant, variantOK := c["variant"].(string)

	if variantOK && templateOK {
		if p.flowTag == "" {
			return errors.New("The required `flow_tag` property (`string`) is either missing or of the wrong type.")
		}

		if f, err := job.GetOrCreateFlow(p.flowTag, variant, template); err != nil {
			return err
		} else {
			p.flow = f
		}
	}

	if interval, ok := c["interval"].(int); ok {
		p.expiration = time.Duration(interval*3) * time.Second

		p.PluginHelper.AddTaskWithClosure(p.performAllTasks, time.Duration(interval)*time.Second)
	} else if interval, ok := c["interval"].(string); ok {
		if timeInterval, err := config.ParseTimeInterval(interval); err == nil {
			if p.expiration == 0 {
				p.expiration = timeInterval * 3.0
			}

			p.PluginHelper.AddTaskWithClosure(p.performAllTasks, timeInterval)
		} else {
			return err
		}
	} else {
		p.PluginHelper.AddTaskWithClosure(p.performAllTasks, 0)
	}

	if p.expiration > 0 && p.expiration < time.Second*60 {
		p.expiration = time.Second * 60
	}

	switch c["expiration"].(type) {
	case int:
		p.expiration = time.Duration(c["expiration"].(int)) * time.Second

	case int64:
		p.expiration = time.Duration(c["expiration"].(int64)) * time.Second

	case string:
		if timeInterval, err := config.ParseTimeInterval(c["expiration"].(string)); err == nil {
			p.expiration = timeInterval
		} else {
			return errors.New("Invalid expiration value. Must be either a number of seconds or a time interval string.")
		}
	}

	if p.expiration < 0 {
		return errors.New("Invalid expiration time")
	}

	if p.expiration > 0 {
		job.Debugf("Expiration is set to %dµs", p.expiration)
	} else {
		job.Debugf("Expiration is off.")
	}

	return nil
}
開發者ID:nagyistge,項目名稱:gotelemetry_agent,代碼行數:101,代碼來源:process.go


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