Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1892)

Unified Diff: appengine/cmd/dm/distributor/notify_execution.go

Issue 1537883002: Initial distributor implementation (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-go@master
Patch Set: self review Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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))
+}

Powered by Google App Engine
This is Rietveld 408576698