pulsar_job.go raw
1 package pulsar
2
3 // Job wraps an NS1 pulsar/apps/{appid}/jobs/{jobid} resource
4 type Job struct {
5 Customer int `json:"customer,omitempty"`
6 TypeID string `json:"typeid"`
7 Name string `json:"name"`
8 Community bool `json:"community,omitempty"`
9 JobID string `json:"jobid,omitempty"`
10 AppID string `json:"appid"`
11 Active bool `json:"active"`
12 Shared bool `json:"shared"`
13 Config *JobConfig `json:"config,omitempty"`
14 }
15
16 // JobConfig config parameter struct
17 type JobConfig struct {
18 Host *string `json:"host"`
19 URLPath *string `json:"url_path"`
20 HTTP *bool `json:"http,omitempty"`
21 HTTPS *bool `json:"https,omitempty"`
22 RequestTimeoutMillis *int `json:"request_timeout_millis,omitempty"`
23 JobTimeoutMillis *int `json:"job_timeout_millis,omitempty"`
24 UseXHR *bool `json:"use_xhr,omitempty"`
25 StaticValues *bool `json:"static_values,omitempty"`
26 BlendMetricWeights *BlendMetricWeights `json:"blend_metric_weights,omitempty"`
27 }
28
29 // BlendMetricWeights parameter struct
30 type BlendMetricWeights struct {
31 Timestamp int `json:"timestamp"`
32 Weights []*Weights `json:"weights"`
33 }
34
35 // Weights parameter struct
36 type Weights struct {
37 Name string `json:"name,omitempty"`
38 Weight int `json:"weight"`
39 DefaultValue float64 `json:"default_value"`
40 Maximize bool `json:"maximize"`
41 }
42
43 // NewJSPulsarJob takes a name, appid, host and urlPath and creates a JavaScript Pulsar job (type *Job)
44 func NewJSPulsarJob(name string, appid string, host string, urlPath string) *Job {
45 return &Job{
46 Name: name,
47 TypeID: "latency",
48 AppID: appid,
49 Config: &JobConfig{
50 Host: &host,
51 URLPath: &urlPath,
52 },
53 }
54 }
55
56 // NewBBPulsarJob takes a name and appid and creates a Bulk Beacon Pulsar job (type *PulsarJob)
57 func NewBBPulsarJob(name string, appid string) *Job {
58 return &Job{
59 Name: name,
60 TypeID: "custom",
61 AppID: appid,
62 }
63 }
64