go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/cipd/appengine/impl/repo/processing/processor.go (about) 1 // Copyright 2018 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 processing 16 17 import ( 18 "context" 19 20 "go.chromium.org/luci/cipd/appengine/impl/model" 21 ) 22 23 // Processor runs some post-processing step on a package instance after it has 24 // been uploaded. 25 type Processor interface { 26 // ID is unique identifier of this processor used store processing results in 27 // the datastore. 28 ID() string 29 30 // Applicable returns true if this processor should be applied to an instance. 31 // 32 // Called as a part of the instance registration datastore transaction. 33 // Returns an error if the decision can't be made. It will result in 34 // a transient instance registration error. 35 Applicable(ctx context.Context, inst *model.Instance) (bool, error) 36 37 // Run executes the processing on the package instance. 38 // 39 // Returns either a result, or a transient error. All fatal errors should be 40 // communicated through the result. 41 // 42 // Must be idempotent. The processor may be called multiple times when 43 // retrying task queue tasks. 44 Run(ctx context.Context, inst *model.Instance, pkg *PackageReader) (Result, error) 45 } 46 47 // Result is returned by processors. 48 // 49 // It is either some JSON-serializable data or a fatal error. 50 type Result struct { 51 Result any // JSON-serializable summary extracted by the processor 52 Err error // if non-nil, contains the fatal error message 53 }