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


Golang WorkSpecMeta.CanStartContinuous方法代码示例

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


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

示例1: getWorkFromSpec

// getWorkFromSpec forcibly retrieves a work unit from a work spec.
// It could create a work unit if spec is a continuous spec with no
// available units.  It ignores other constraints, such as whether the
// work spec is paused.
func (w *worker) getWorkFromSpec(spec *workSpec, meta *coordinate.WorkSpecMeta) *attempt {
	var unit *workUnit
	now := w.Coordinate().clock.Now()
	if len(spec.available) != 0 {
		unit = spec.available.Next()
	} else if meta.CanStartContinuous(now) {
		// Make a brand new work unit.  Its key is the string
		// form of a time_t.
		seconds := now.Unix()
		nano := now.Nanosecond()
		milli := nano / 1000000
		name := fmt.Sprintf("%d.%03d", seconds, milli)
		var exists bool
		unit, exists = spec.workUnits[name]
		if !exists {
			unit = &workUnit{
				name:     name,
				data:     map[string]interface{}{},
				workSpec: spec,
			}
			spec.workUnits[name] = unit
		}
		spec.meta.NextContinuous = now.Add(meta.Interval)
	} else {
		return nil
	}
	return w.makeAttempt(unit, time.Duration(0))
}
开发者ID:dmaze,项目名称:goordinate,代码行数:32,代码来源:worker.go

示例2: requestAttemptsForSpec

func (w *worker) requestAttemptsForSpec(req coordinate.AttemptRequest, spec *workSpec, meta *coordinate.WorkSpecMeta) ([]coordinate.Attempt, error) {
	var (
		attempts []coordinate.Attempt
		count    int
		err      error
	)

	// Adjust the work unit count based on what's possible here
	count = req.NumberOfWorkUnits
	if count < 1 {
		count = 1
	}
	if meta.MaxAttemptsReturned > 0 && count > meta.MaxAttemptsReturned {
		count = meta.MaxAttemptsReturned
	}
	if meta.MaxRunning > 0 && count > meta.MaxRunning-meta.PendingCount {
		count = meta.MaxRunning - meta.PendingCount
	}

	// Now choose units and create attempts
	err = withTx(w, func(tx *sql.Tx) error {
		units, err := w.chooseWorkUnits(tx, spec, count)
		if err != nil {
			return err
		}
		now := w.Coordinate().clock.Now()
		if len(units) == 0 && meta.CanStartContinuous(now) {
			units, err = w.createContinuousUnits(tx, spec, meta)
		}
		if err != nil {
			return err
		}
		length := time.Duration(15) * time.Minute
		for _, unit := range units {
			a, err := makeAttempt(tx, unit, w, length)
			if err != nil {
				return err
			}
			attempts = append(attempts, a)
		}
		return nil
	})
	return attempts, err
}
开发者ID:dmaze,项目名称:goordinate,代码行数:44,代码来源:attempt.go


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