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

Unified Diff: appengine/cmd/dm/distributor/impl/jobsim/job.go

Issue 1537883002: Initial distributor implementation (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-go@master
Patch Set: work in progress Created 4 years, 11 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/impl/jobsim/job.go
diff --git a/appengine/cmd/dm/distributor/impl/jobsim/job.go b/appengine/cmd/dm/distributor/impl/jobsim/job.go
new file mode 100644
index 0000000000000000000000000000000000000000..0c174e11f2ab84cab4895801c02a871dbf6952e3
--- /dev/null
+++ b/appengine/cmd/dm/distributor/impl/jobsim/job.go
@@ -0,0 +1,54 @@
+// Copyright 2015 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 jobsim
+
+import (
+ "encoding/json"
+ "fmt"
+
+ "github.com/luci/luci-go/appengine/cmd/dm/distributor"
+ "github.com/luci/luci-go/appengine/cmd/dm/distributor/impl/jobsim/parser"
+ "github.com/luci/luci-go/appengine/cmd/dm/distributor/protos/jobsim"
+ "github.com/luci/luci-go/appengine/cmd/dm/enums/execution"
+)
+
+type Job struct {
+ GroupSeed int64
+ Uniq int64
+ Phrase parser.Phrase
+ PreviousState distributor.PersistentState
+
+ // execution information
+ State execution.State
+ PersistentState distributor.PersistentState
+}
+
+type questData struct {
+ GroupSeed int64 `json:",string"`
+ Uniq int64 `json:",string"`
+ Phrase string
+}
+
+func MakeJob(cfg *jobsim.Config, t distributor.TaskDescription) (*Job, error) {
+ q := &questData{}
+
+ err := json.Unmarshal(t.Payload(), q)
+ if err != nil {
+ return nil, err
+ }
+
+ if q.GroupSeed == 0 || q.Phrase == "" {
+ return nil, fmt.Errorf("incomplete job payload")
+ }
+
+ ret := &Job{
+ GroupSeed: q.GroupSeed,
+ Uniq: q.Uniq,
+ State: execution.Scheduled,
+ PreviousState: t.PreviousState(),
+ }
+ ret.Phrase, err = parser.ParsePhrase(q.Phrase)
+ return ret, err
+}

Powered by Google App Engine
This is Rietveld 408576698