-
Notifications
You must be signed in to change notification settings - Fork 21
/
workunitUniqueIdentifier.go
83 lines (60 loc) · 2.07 KB
/
workunitUniqueIdentifier.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
package core
import (
"fmt"
"github.com/mitchellh/mapstructure"
"strconv"
"strings"
)
type Workunit_Unique_Identifier struct {
Task_Unique_Identifier `bson:",inline" json:",inline" mapstructure:",squash"` // TaskName, Workflow, JobId
Rank int `bson:"rank" json:"rank" mapstructure:"rank"` // this is the local identifier
}
func New_Workunit_Unique_Identifier(task Task_Unique_Identifier, rank int) (wui Workunit_Unique_Identifier) {
wui = Workunit_Unique_Identifier{}
wui.Task_Unique_Identifier = task
wui.Rank = rank
return
}
func (w Workunit_Unique_Identifier) String() (work_str string, err error) {
var task_string string
task_string, err = w.Task_Unique_Identifier.String()
work_str = fmt.Sprintf("%s_%d", task_string, w.Rank)
return
}
func (w Workunit_Unique_Identifier) GetTask() Task_Unique_Identifier {
return w.Task_Unique_Identifier
}
func New_Workunit_Unique_Identifier_from_interface(original interface{}) (wui Workunit_Unique_Identifier, err error) {
wui = Workunit_Unique_Identifier{}
err = mapstructure.Decode(original, &wui)
if err != nil {
err = fmt.Errorf("(New_Workunit_Unique_Identifier_from_interface) mapstructure returs: %s", err.Error())
return
}
return
}
func New_Workunit_Unique_Identifier_FromString(old_style_id string) (w Workunit_Unique_Identifier, err error) {
array := strings.Split(old_style_id, "_")
//if len(array) != 3 {
// err = fmt.Errorf("Cannot parse workunit identifier: %s", old_style_id)
// return
//}
a_len := len(array)
rank_string := array[a_len-1]
rank, err := strconv.Atoi(rank_string)
if err != nil {
return
}
prefix := ""
if len(array) > 1 {
prefix = strings.Join(array[0:a_len-1], "_")
}
var t Task_Unique_Identifier
t, err = New_Task_Unique_Identifier_FromString(prefix)
if err != nil {
err = fmt.Errorf("(New_Workunit_Unique_Identifier_FromString) New_Task_Unique_Identifier_FromString returns: %s (prefix=%s, old_style_id=%s)", err.Error(), prefix, old_style_id)
return
}
w = New_Workunit_Unique_Identifier(t, rank)
return
}