go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/server/tq/txn/spanner/init.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 // Spanner contains Transactional Enqueue support for Cloud Spanner. 16 // 17 // Importing this package adds Cloud Spanner transactions support to server/tq's 18 // AddTask. Works only for transactions initiated via server/span library 19 // (see ReadWriteTransaction there). 20 // 21 // This package is normally imported unnamed: 22 // 23 // import _ "go.chromium.org/luci/server/tq/txn/spanner" 24 package spanner 25 26 import ( 27 "context" 28 29 "go.chromium.org/luci/server/span" 30 "go.chromium.org/luci/server/tq/internal/db" 31 "go.chromium.org/luci/server/tq/internal/lessor" 32 ) 33 34 var impl spanDB 35 36 func init() { 37 db.Register(db.Impl{ 38 Kind: impl.Kind(), 39 Module: span.ModuleName, 40 ProbeForTxn: func(ctx context.Context) db.DB { 41 if span.RW(ctx) != nil { 42 return impl 43 } 44 return nil 45 }, 46 NonTxn: func(ctx context.Context) db.DB { 47 return impl 48 }, 49 }) 50 } 51 52 func init() { 53 lessor.Register("spanner", func(context.Context) (lessor.Lessor, error) { 54 return &spanLessor{}, nil 55 }) 56 }