go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/server/tq/default.go (about) 1 // Copyright 2020 The LUCI Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package tq 16 17 import ( 18 "context" 19 ) 20 21 // Default is a dispatcher installed into the server when using NewModule or 22 // NewModuleFromFlags. 23 // 24 // The module takes care of configuring this dispatcher based on the server 25 // environment and module's options. 26 // 27 // You still need to register your tasks in it using RegisterTaskClass. 28 var Default Dispatcher 29 30 // RegisterTaskClass is a shortcut for Default.RegisterTaskClass. 31 func RegisterTaskClass(t TaskClass) TaskClassRef { 32 return Default.RegisterTaskClass(t) 33 } 34 35 // AddTask is a shortcut for Default.AddTask. 36 func AddTask(ctx context.Context, task *Task) error { 37 return Default.AddTask(ctx, task) 38 } 39 40 // MustAddTask is like AddTask, but panics on errors. 41 // 42 // Mostly useful for AddTask calls inside a Spanner transaction, where they 43 // essentially just call span.BufferWrite (i.e. make no RPCs) and thus can fail 44 // only if arguments are bad (in which case it is OK to panic). 45 func MustAddTask(ctx context.Context, task *Task) { 46 if err := AddTask(ctx, task); err != nil { 47 panic(err) 48 } 49 } 50 51 // Sweep is a shortcut for Default.Sweep. 52 func Sweep(ctx context.Context) error { 53 return Default.Sweep(ctx) 54 }