Chromium Code Reviews| Index: appengine/cmd/dm/distributor/notify_execution.go |
| diff --git a/appengine/cmd/dm/distributor/notify_execution.go b/appengine/cmd/dm/distributor/notify_execution.go |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..88d567d7739b50031fb2dc57db7de010a6fc403b |
| --- /dev/null |
| +++ b/appengine/cmd/dm/distributor/notify_execution.go |
| @@ -0,0 +1,50 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package distributor |
| + |
| +import ( |
| + "github.com/luci/gae/service/datastore" |
| + "github.com/luci/luci-go/appengine/cmd/dm/model" |
| + "github.com/luci/luci-go/appengine/tumble" |
| + "github.com/luci/luci-go/common/logging" |
| + "golang.org/x/net/context" |
| +) |
| + |
| +// NotifyExecution is used to finish an execution. Specifically it allows the |
| +// appropriate distributor to HandleNotification, and then when that concludes, |
| +// invokes DM's FinishExecution (see mutate.FinishExecution). |
| +type NotifyExecution struct { |
| + CfgName string |
| + Notification *Notification |
| +} |
| + |
| +// Root implements tumble.Mutation. |
| +func (f *NotifyExecution) Root(c context.Context) *datastore.Key { |
| + return model.ExecutionKeyFromID(c, f.Notification.ID) |
| +} |
| + |
| +// RollForward implements tumble.Mutation. |
| +func (f *NotifyExecution) RollForward(c context.Context) (muts []tumble.Mutation, err error) { |
| + reg := GetRegistry(c) |
| + dist, _, err := reg.MakeDistributor(c, f.CfgName) |
| + if err != nil { |
| + 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.
|
| + return |
| + } |
| + rslt, err := dist.HandleNotification(f.Notification) |
| + if err != nil { |
| + // TODO(riannucci): check for transient/non-transient |
| + logging.Fields{"error": err, "cfg": f.CfgName}.Errorf(c, "Failed to handle notification") |
| + return |
| + } |
| + if rslt != nil { |
| + return reg.FinishExecution(c, f.Notification.ID, rslt) |
| + } |
| + return |
| +} |
| + |
| +func init() { |
| + tumble.Register((*NotifyExecution)(nil)) |
| +} |