@ -166,15 +166,53 @@ func lookupWorker(ctx context.Context, reader db.Reader, id string) (*Worker, er
}
// ListWorkers will return a listing of Workers and honor the WithLimit option.
// Supported options: WithWorkerType, WithActiveWorkers, WithLiveness,
// WithWorkerPool, WithLimit
//
// If WithLiveness is zero the default liveness value is used, if it is negative
// then the last status update time is ignored.
// If WithLimit < 0, then unlimited results are returned. If WithLimit == 0, then
// default limits are used for results. WithWorkerPool can be provided with a
// non-zero length slice of worker ids to restrict the returned workers to only
// ones with the ids provided.
// Also supports: WithWorkerType, WithActiveWorkers
func ( r * Repository ) ListWorkers ( ctx context . Context , scopeIds [ ] string , opt ... Option ) ( [ ] * Worker , error ) {
const op = "server.(Repository).ListWorkers"
opts := GetOpts ( opt ... )
newOpts := [ ] Option { }
// handle the WithLimit default for the repo
switch {
case opts . withLimit != 0 :
newOpts = append ( newOpts , WithLimit ( opts . withLimit ) )
default :
newOpts = append ( newOpts , WithLimit ( r . defaultLimit ) )
}
// handle the WithLiveness default
switch {
case opts . withLiveness != 0 :
newOpts = append ( newOpts , WithLiveness ( opts . withLiveness ) )
default :
newOpts = append ( newOpts , WithLiveness ( DefaultLiveness ) )
}
newOpts = append ( newOpts , WithWorkerType ( opts . withWorkerType ) )
newOpts = append ( newOpts , WithActiveWorkers ( opts . withActiveWorkers ) )
newOpts = append ( newOpts , WithWorkerPool ( opts . withWorkerPool ) )
return ListWorkers ( ctx , r . reader , scopeIds , newOpts ... )
}
// ListWorkers will return a listing of Workers and honor the WithLimit option.
// Supported options: WithWorkerType, WithActiveWorkers, WithLiveness,
// WithWorkerPool, WithLimit
//
// If WithLiveness is zero the default liveness value is used, if it is negative
// then the last status update time is ignored.
// If WithLimit < 0, then unlimited results are returned. If WithLimit == 0, then
// default limits are used for results. WithWorkerPool can be provided with a
// non-zero length slice of worker ids to restrict the returned workers to only
// ones with the ids provided.
func ListWorkers ( ctx context . Context , reader db . Reader , scopeIds [ ] string , opt ... Option ) ( [ ] * Worker , error ) {
const op = "server.ListWorkers"
switch {
case len ( scopeIds ) == 0 :
return nil , errors . New ( ctx , errors . InvalidParameter , op , "no scope ids set" )
@ -215,14 +253,14 @@ func (r *Repository) ListWorkers(ctx context.Context, scopeIds []string, opt ...
whereArgs = append ( whereArgs , opts . withWorkerPool )
}
limit := r. d efaultLimit
limit := db. D efaultLimit
if opts . withLimit != 0 {
// non-zero signals an override of the default limit for the repo.
limit = opts . withLimit
}
var wAggs [ ] * workerAggregate
if err := r . r eader. SearchWhere (
if err := r eader. SearchWhere (
ctx ,
& wAggs ,
strings . Join ( where , " and " ) ,