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 |
+} |