Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package distributor | |
| 6 | |
| 7 import ( | |
| 8 "github.com/luci/gae/service/datastore" | |
| 9 "github.com/luci/luci-go/appengine/cmd/dm/model" | |
| 10 "github.com/luci/luci-go/appengine/tumble" | |
| 11 "github.com/luci/luci-go/common/logging" | |
| 12 "golang.org/x/net/context" | |
| 13 ) | |
| 14 | |
| 15 // NotifyExecution is used to finish an execution. Specifically it allows the | |
| 16 // appropriate distributor to HandleNotification, and then when that concludes, | |
| 17 // invokes DM's FinishExecution (see mutate.FinishExecution). | |
| 18 type NotifyExecution struct { | |
| 19 CfgName string | |
| 20 Notification *Notification | |
| 21 } | |
| 22 | |
| 23 // Root implements tumble.Mutation. | |
| 24 func (f *NotifyExecution) Root(c context.Context) *datastore.Key { | |
| 25 return model.ExecutionKeyFromID(c, f.Notification.ID) | |
| 26 } | |
| 27 | |
| 28 // RollForward implements tumble.Mutation. | |
| 29 func (f *NotifyExecution) RollForward(c context.Context) (muts []tumble.Mutation , err error) { | |
| 30 reg := GetRegistry(c) | |
| 31 dist, _, err := reg.MakeDistributor(c, f.CfgName) | |
| 32 if err != nil { | |
| 33 logging.Fields{"error": err, "cfg": f.CfgName}.Errorf(c, "Failed to make distributor") | |
|
dnj (Google)
2016/06/09 18:00:55
nit: logging.ErrorKey
iannucci
2016/06/15 00:46:00
Done.
| |
| 34 return | |
| 35 } | |
| 36 rslt, err := dist.HandleNotification(f.Notification) | |
| 37 if err != nil { | |
| 38 // TODO(riannucci): check for transient/non-transient | |
| 39 logging.Fields{"error": err, "cfg": f.CfgName}.Errorf(c, "Failed to handle notification") | |
| 40 return | |
| 41 } | |
| 42 if rslt != nil { | |
| 43 return reg.FinishExecution(c, f.Notification.ID, rslt) | |
| 44 } | |
| 45 return | |
| 46 } | |
| 47 | |
| 48 func init() { | |
| 49 tumble.Register((*NotifyExecution)(nil)) | |
| 50 } | |
| OLD | NEW |