Beispiel #1
0
func parseTask(task *Task) error {
	args, err := utils.ToStringArray(task.Command)
	if err != nil {
		return err
	}
	task.Args = args
	if task.Args == nil || len(task.Args) == 0 {
		return fmt.Errorf("Task did not provide a command")
	}
	if task.Name == "" {
		task.Name = strings.Join(task.Args, " ")
	}
	freq, err := utils.ParseDuration(task.Frequency)
	if err != nil {
		return fmt.Errorf("Unable to parse frequency %s: %v", task.Frequency, err)
	}
	if freq < time.Millisecond {
		return fmt.Errorf("Frequency %v cannot be less that %v", freq, taskMinDuration)
	}
	task.freqDuration = freq
	task.timeoutDuration = freq
	if task.Timeout != "" {
		timeout, err := utils.ParseDuration(task.Timeout)
		if err != nil {
			return fmt.Errorf("Unable to parse timeout %s: %v", task.Timeout, err)
		}
		if timeout < taskMinDuration {
			return fmt.Errorf("Timeout %v cannot be less that %v", timeout, taskMinDuration)
		}
		task.timeoutDuration = timeout
	} else {
		task.Timeout = task.Frequency
	}
	return nil
}
Beispiel #2
0
func parseTask(task *Task) error {

	if task.Command == nil {
		return fmt.Errorf("Task did not provide a command")
	}

	freq, err := utils.ParseDuration(task.Frequency)
	if err != nil {
		return fmt.Errorf("Unable to parse frequency %s: %v", task.Frequency, err)
	}
	if freq < time.Millisecond {
		return fmt.Errorf("Frequency %v cannot be less that %v", freq, taskMinDuration)
	}
	task.freqDuration = freq

	if task.Timeout == "" {
		task.Timeout = task.Frequency
	}
	cmd, err := commands.NewCommand(task.Command, task.Timeout)
	if cmd.TimeoutDuration < taskMinDuration {
		return fmt.Errorf("Timeout %v cannot be less that %v", cmd.TimeoutDuration, taskMinDuration)
	}
	cmd.Name = fmt.Sprintf("task[%s]", task.Name)
	task.cmd = cmd

	return nil
}
Beispiel #3
0
func getTimeout(timeoutFmt string) (time.Duration, error) {
	if timeoutFmt != "" {
		timeout, err := utils.ParseDuration(timeoutFmt)
		if err != nil {
			return time.Duration(0), err
		}
		return timeout, nil
	}
	// support commands that don't have a timeout for backwards
	// compatibility
	return time.Duration(0), nil
}