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


Golang WorkSpecMeta.PendingCount方法代码示例

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


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

示例1: Meta

func (spec *workSpec) Meta(withCounts bool) (coordinate.WorkSpecMeta, error) {
	// If we need counts, we need to run expiry so that the
	// available/pending counts are rightish
	if withCounts {
		_ = withTx(spec, func(tx *sql.Tx) error {
			return expireAttempts(spec, tx)
		})
	}
	var meta coordinate.WorkSpecMeta
	err := withTx(spec, func(tx *sql.Tx) error {
		var (
			query          string
			interval       string
			nextContinuous pq.NullTime
		)
		query = buildSelect([]string{
			workSpecPriority,
			workSpecWeight,
			workSpecPaused,
			workSpecContinuous,
			workSpecCanBeContinuous,
			workSpecMinMemoryGb,
			workSpecInterval,
			workSpecNextContinuous,
			workSpecMaxRunning,
			workSpecMaxAttemptsReturned,
			workSpecNextWorkSpec,
		}, []string{
			workSpecTable,
		}, []string{
			isWorkSpec, // binds $1
		})
		row := tx.QueryRow(query, spec.id)
		err := row.Scan(
			&meta.Priority,
			&meta.Weight,
			&meta.Paused,
			&meta.Continuous,
			&meta.CanBeContinuous,
			&meta.MinMemoryGb,
			&interval,
			&nextContinuous,
			&meta.MaxRunning,
			&meta.MaxAttemptsReturned,
			&meta.NextWorkSpecName,
		)
		if err != nil {
			return err
		}
		meta.NextContinuous = nullTimeToTime(nextContinuous)
		meta.Interval, err = sqlToDuration(interval)
		if err != nil {
			return err
		}

		// Find counts with a second query, if requested
		if !withCounts {
			return nil
		}
		query = buildSelect([]string{
			attemptStatus,
			"COUNT(*)",
		}, []string{
			workUnitAttemptJoin,
		}, []string{
			inThisWorkSpec, // binds $1
		})
		query += " GROUP BY " + attemptStatus
		rows, err := tx.Query(query, spec.id)
		if err != nil {
			return err
		}
		return scanRows(rows, func() error {
			var status sql.NullString
			var count int
			err := rows.Scan(&status, &count)
			if err != nil {
				return err
			}
			if !status.Valid {
				meta.AvailableCount += count
			} else {
				switch status.String {
				case "expired":
					meta.AvailableCount += count
				case "retryable":
					meta.AvailableCount += count
				case "pending":
					meta.PendingCount += count
				}
			}
			return nil
		})
	})
	return meta, err
}
开发者ID:dmaze,项目名称:goordinate,代码行数:96,代码来源:work_spec.go


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