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
|
package protocol
import (
"github.com/spiral/errors"
"go.temporal.io/sdk/converter"
"go.temporal.io/sdk/worker"
)
// WorkerInfo outlines information about every available worker and it's TaskQueues.
// WorkerInfo lists available task queues, workflows and activities.
type WorkerInfo struct {
// TaskQueue assigned to the worker.
TaskQueue string `json:"taskQueue"`
// Options describe worker options.
Options worker.Options `json:"options,omitempty"`
// Workflows provided by the worker.
Workflows []WorkflowInfo
// Activities provided by the worker.
Activities []ActivityInfo
}
// WorkflowInfo describes single worker workflow.
type WorkflowInfo struct {
// Name of the workflow.
Name string `json:"name"`
// Queries pre-defined for the workflow type.
Queries []string `json:"queries"`
// Signals pre-defined for the workflow type.
Signals []string `json:"signals"`
}
// ActivityInfo describes single worker activity.
type ActivityInfo struct {
// Name describes public activity name.
Name string `json:"name"`
}
// FetchWorkerInfo fetches information about all underlying workers (can be multiplexed inside single process).
func FetchWorkerInfo(c Codec, e Endpoint, dc converter.DataConverter) ([]WorkerInfo, error) {
const op = errors.Op("fetch_worker_info")
result, err := c.Execute(e, Context{}, Message{ID: 0, Command: GetWorkerInfo{}})
if err != nil {
return nil, errors.E(op, err)
}
if len(result) != 1 {
return nil, errors.E(op, errors.Str("unable to read worker info"))
}
if result[0].ID != 0 {
return nil, errors.E(op, errors.Str("FetchWorkerInfo confirmation missing"))
}
var info []WorkerInfo
for i := range result[0].Payloads.Payloads {
wi := WorkerInfo{}
if err := dc.FromPayload(result[0].Payloads.Payloads[i], &wi); err != nil {
return nil, errors.E(op, err)
}
info = append(info, wi)
}
return info, nil
}
|