OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be 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{ |
| 34 logging.ErrorKey: err, |
| 35 "cfg": f.CfgName, |
| 36 }.Errorf(c, "Failed to make distributor") |
| 37 return |
| 38 } |
| 39 rslt, err := dist.HandleNotification(f.Notification) |
| 40 if err != nil { |
| 41 // TODO(riannucci): check for transient/non-transient |
| 42 logging.Fields{ |
| 43 logging.ErrorKey: err, |
| 44 "cfg": f.CfgName, |
| 45 }.Errorf(c, "Failed to handle notification") |
| 46 return |
| 47 } |
| 48 if rslt != nil { |
| 49 return reg.FinishExecution(c, f.Notification.ID, rslt) |
| 50 } |
| 51 return |
| 52 } |
| 53 |
| 54 func init() { |
| 55 tumble.Register((*NotifyExecution)(nil)) |
| 56 } |
OLD | NEW |