-
Notifications
You must be signed in to change notification settings - Fork 21
/
cwl_workunit_result.go
92 lines (76 loc) · 2.71 KB
/
cwl_workunit_result.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package core
import (
"github.com/MG-RAST/AWE/lib/core/cwl"
"github.com/MG-RAST/AWE/lib/logger"
//cwl_types "github.com/MG-RAST/AWE/lib/core/cwl/types"
//"github.com/davecgh/go-spew/spew"
"fmt"
)
// TODO core.Notice and this should be the same !!!!
// Notice _
type Notice struct {
ID Workunit_Unique_Identifier `bson:"id" json:"id" mapstructure:"id"` // redundant field, for reporting
WorkerID string `bson:"worker_id" json:"worker_id" mapstructure:"worker_id"`
Results *cwl.Job_document `bson:"results" json:"results" mapstructure:"results"` // subset of tool_results with Shock URLs
Status string `bson:"status,omitempty" json:"status,omitempty" mapstructure:"status,omitempty"` // this is redundant as workunit already has state, but this is only used for transfer
ComputeTime int `bson:"computetime,omitempty" json:"computetime,omitempty" mapstructure:"computetime,omitempty"`
Notes string
Stderr string
}
//type Notice struct {
// WorkId Workunit_Unique_Identifier
// Status string
// WorkerId string
// ComputeTime int
// Notes string
// Stderr string
//}
// NewNotice _
func NewNotice(native interface{}, context *cwl.WorkflowContext) (workunitResult *Notice, err error) {
workunitResult = &Notice{}
switch native.(type) {
case map[string]interface{}:
nativeMap, ok := native.(map[string]interface{})
if !ok {
err = fmt.Errorf("(NewNotice) type error")
return
}
results, hasResults := nativeMap["results"]
if hasResults {
if results != nil {
var resultsJobdoc *cwl.Job_document
resultsJobdoc, err = cwl.NewJob_documentFromNamedTypes(results, context)
if err != nil {
err = fmt.Errorf("(NewNotice) NewJob_documentFromNamedTypes returns %s", err.Error())
return
}
workunitResult.Results = resultsJobdoc
} else {
logger.Debug(2, "(NewNotice) results == nil")
}
} else {
logger.Debug(2, "(NewNotice) no results")
}
id, ok := nativeMap["id"]
if !ok {
err = fmt.Errorf("(NewNotice) id is missing")
return
}
workunitResult.ID, err = New_Workunit_Unique_Identifier_from_interface(id)
if err != nil {
err = fmt.Errorf("(NewNotice) New_Workunit_Unique_Identifier_from_interface returned: %s", err.Error())
return
}
workunitResult.WorkerID, _ = nativeMap["worker_id"].(string)
status, hasStatus := nativeMap["status"]
if !hasStatus {
err = fmt.Errorf("(NewNotice) status is missing")
return
}
workunitResult.Status, _ = status.(string)
workunitResult.ComputeTime, _ = nativeMap["computetime"].(int)
default:
err = fmt.Errorf("(NewNotice) wrong type, map expected")
}
return
}