blob: 0bd93cc65b8b9d195b0c92da397478482848fbc9 [file] [log] [blame]
// Copyright 2020 The LUCI Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package invocations
import (
"time"
"cloud.google.com/go/spanner"
"go.chromium.org/luci/resultdb/internal/spanutil"
pb "go.chromium.org/luci/resultdb/proto/v1"
)
func insertInvocation(id ID, extraValues map[string]interface{}) *spanner.Mutation {
future := time.Date(2050, 1, 1, 0, 0, 0, 0, time.UTC)
values := map[string]interface{}{
"InvocationId": id,
"ShardId": 0,
"State": pb.Invocation_FINALIZED,
"Realm": "",
"InvocationExpirationTime": future,
"ExpectedTestResultsExpirationTime": future,
"CreateTime": spanner.CommitTimestamp,
"Deadline": future,
}
updateDict(values, extraValues)
// Ensure a finalized invocation has finalization time.
if _, ok := values["FinalizeTime"]; !ok && values["State"].(pb.Invocation_State) == pb.Invocation_FINALIZED {
values["FinalizeTime"] = spanner.CommitTimestamp
}
return spanutil.InsertMap("Invocations", values)
}
func insertInclusion(including, included ID) *spanner.Mutation {
return spanutil.InsertMap("IncludedInvocations", map[string]interface{}{
"InvocationId": including,
"IncludedInvocationId": included,
})
}
func insertInvocationIncluding(id ID, included ...ID) []*spanner.Mutation {
ms := []*spanner.Mutation{insertInvocation(id, nil)}
for _, incl := range included {
ms = append(ms, insertInclusion(id, incl))
}
return ms
}
func updateDict(dest, source map[string]interface{}) {
for k, v := range source {
dest[k] = v
}
}