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..0470b2413a3735654ba3d8fb772b9b4326aba11f |
--- /dev/null |
+++ b/appengine/cmd/dm/distributor/notify_execution.go |
@@ -0,0 +1,56 @@ |
+// Copyright 2016 The LUCI Authors. All rights reserved. |
+// Use of this source code is governed under the Apache License, Version 2.0 |
+// 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{ |
+ logging.ErrorKey: err, |
+ "cfg": f.CfgName, |
+ }.Errorf(c, "Failed to make distributor") |
+ return |
+ } |
+ rslt, err := dist.HandleNotification(f.Notification) |
+ if err != nil { |
+ // TODO(riannucci): check for transient/non-transient |
+ logging.Fields{ |
+ logging.ErrorKey: 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)) |
+} |