-
Notifications
You must be signed in to change notification settings - Fork 0
/
job.go
215 lines (192 loc) · 8.17 KB
/
job.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
package presenters
import (
"time"
"github.com/google/uuid"
commonassets "github.com/O1MaGnUmO1/chainlink-common/pkg/assets"
"github.com/O1MaGnUmO1/erinaceus-vrf/core/chains/evm/assets"
"github.com/O1MaGnUmO1/erinaceus-vrf/core/chains/evm/utils/big"
clnull "github.com/O1MaGnUmO1/erinaceus-vrf/core/null"
"github.com/O1MaGnUmO1/erinaceus-vrf/core/services/job"
"github.com/O1MaGnUmO1/erinaceus-vrf/core/services/keystore/keys/ethkey"
"github.com/O1MaGnUmO1/erinaceus-vrf/core/services/pipeline"
"github.com/O1MaGnUmO1/erinaceus-vrf/core/services/signatures/secp256k1"
"github.com/O1MaGnUmO1/erinaceus-vrf/core/store/models"
)
// JobSpecType defines the the the spec type of the job
type JobSpecType string
func (t JobSpecType) String() string {
return string(t)
}
const (
DirectRequestJobSpec JobSpecType = "directrequest"
FluxMonitorJobSpec JobSpecType = "fluxmonitor"
OffChainReportingJobSpec JobSpecType = "offchainreporting"
KeeperJobSpec JobSpecType = "keeper"
CronJobSpec JobSpecType = "cron"
VRFJobSpec JobSpecType = "vrf"
WebhookJobSpec JobSpecType = "webhook"
BlockhashStoreJobSpec JobSpecType = "blockhashstore"
BlockHeaderFeederJobSpec JobSpecType = "blockheaderfeeder"
BootstrapJobSpec JobSpecType = "bootstrap"
GatewayJobSpec JobSpecType = "gateway"
)
// DirectRequestSpec defines the spec details of a DirectRequest Job
type DirectRequestSpec struct {
ContractAddress ethkey.EIP55Address `json:"contractAddress"`
MinIncomingConfirmations clnull.Uint32 `json:"minIncomingConfirmations"`
MinContractPayment *commonassets.Link `json:"minContractPaymentLinkJuels"`
Requesters models.AddressCollection `json:"requesters"`
Initiator string `json:"initiator"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
EVMChainID *big.Big `json:"evmChainID"`
}
// PipelineSpec defines the spec details of the pipeline
type PipelineSpec struct {
ID int32 `json:"id"`
JobID int32 `json:"jobID"`
DotDAGSource string `json:"dotDagSource"`
}
// NewPipelineSpec generates a new PipelineSpec from a pipeline.Spec
func NewPipelineSpec(spec *pipeline.Spec) PipelineSpec {
return PipelineSpec{
ID: spec.ID,
JobID: spec.JobID,
DotDAGSource: spec.DotDagSource,
}
}
// WebhookSpec defines the spec details of a Webhook Job
type WebhookSpec struct {
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
// NewWebhookSpec generates a new WebhookSpec from a job.WebhookSpec
func NewWebhookSpec(spec *job.WebhookSpec) *WebhookSpec {
return &WebhookSpec{
CreatedAt: spec.CreatedAt,
UpdatedAt: spec.UpdatedAt,
}
}
type VRFSpec struct {
BatchCoordinatorAddress *ethkey.EIP55Address `json:"batchCoordinatorAddress"`
BatchFulfillmentEnabled bool `json:"batchFulfillmentEnabled"`
CustomRevertsPipelineEnabled *bool `json:"customRevertsPipelineEnabled,omitempty"`
BatchFulfillmentGasMultiplier float64 `json:"batchFulfillmentGasMultiplier"`
CoordinatorAddress ethkey.EIP55Address `json:"coordinatorAddress"`
PublicKey secp256k1.PublicKey `json:"publicKey"`
FromAddresses []ethkey.EIP55Address `json:"fromAddresses"`
PollPeriod models.Duration `json:"pollPeriod"`
MinIncomingConfirmations uint32 `json:"confirmations"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
EVMChainID *big.Big `json:"evmChainID"`
ChunkSize uint32 `json:"chunkSize"`
RequestTimeout models.Duration `json:"requestTimeout"`
BackoffInitialDelay models.Duration `json:"backoffInitialDelay"`
BackoffMaxDelay models.Duration `json:"backoffMaxDelay"`
GasLanePrice *assets.Wei `json:"gasLanePrice"`
RequestedConfsDelay int64 `json:"requestedConfsDelay"`
VRFOwnerAddress *ethkey.EIP55Address `json:"vrfOwnerAddress,omitempty"`
}
func NewVRFSpec(spec *job.VRFSpec) *VRFSpec {
return &VRFSpec{
BatchCoordinatorAddress: spec.BatchCoordinatorAddress,
BatchFulfillmentEnabled: spec.BatchFulfillmentEnabled,
BatchFulfillmentGasMultiplier: float64(spec.BatchFulfillmentGasMultiplier),
CustomRevertsPipelineEnabled: &spec.CustomRevertsPipelineEnabled,
CoordinatorAddress: spec.CoordinatorAddress,
PublicKey: spec.PublicKey,
FromAddresses: spec.FromAddresses,
PollPeriod: models.MustMakeDuration(spec.PollPeriod),
MinIncomingConfirmations: spec.MinIncomingConfirmations,
CreatedAt: spec.CreatedAt,
UpdatedAt: spec.UpdatedAt,
EVMChainID: spec.EVMChainID,
ChunkSize: spec.ChunkSize,
RequestTimeout: models.MustMakeDuration(spec.RequestTimeout),
BackoffInitialDelay: models.MustMakeDuration(spec.BackoffInitialDelay),
BackoffMaxDelay: models.MustMakeDuration(spec.BackoffMaxDelay),
GasLanePrice: spec.GasLanePrice,
RequestedConfsDelay: spec.RequestedConfsDelay,
VRFOwnerAddress: spec.VRFOwnerAddress,
}
}
type GatewaySpec struct {
GatewayConfig map[string]interface{} `json:"gatewayConfig"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
func NewGatewaySpec(spec *job.GatewaySpec) *GatewaySpec {
return &GatewaySpec{
GatewayConfig: spec.GatewayConfig,
CreatedAt: spec.CreatedAt,
UpdatedAt: spec.UpdatedAt,
}
}
// JobError represents errors on the job
type JobError struct {
ID int64 `json:"id"`
Description string `json:"description"`
Occurrences uint `json:"occurrences"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
func NewJobError(e job.SpecError) JobError {
return JobError{
ID: e.ID,
Description: e.Description,
Occurrences: e.Occurrences,
CreatedAt: e.CreatedAt,
UpdatedAt: e.UpdatedAt,
}
}
// JobResource represents a JobResource
type JobResource struct {
JAID
Name string `json:"name"`
Type JobSpecType `json:"type"`
SchemaVersion uint32 `json:"schemaVersion"`
GasLimit clnull.Uint32 `json:"gasLimit"`
ForwardingAllowed bool `json:"forwardingAllowed"`
MaxTaskDuration models.Interval `json:"maxTaskDuration"`
ExternalJobID uuid.UUID `json:"externalJobID"`
VRFSpec *VRFSpec `json:"vrfSpec"`
WebhookSpec *WebhookSpec `json:"webhookSpec"`
GatewaySpec *GatewaySpec `json:"gatewaySpec"`
PipelineSpec PipelineSpec `json:"pipelineSpec"`
Errors []JobError `json:"errors"`
}
// NewJobResource initializes a new JSONAPI job resource
func NewJobResource(j job.Job) *JobResource {
resource := &JobResource{
JAID: NewJAIDInt32(j.ID),
Name: j.Name.ValueOrZero(),
Type: JobSpecType(j.Type),
SchemaVersion: j.SchemaVersion,
GasLimit: j.GasLimit,
ForwardingAllowed: j.ForwardingAllowed,
MaxTaskDuration: j.MaxTaskDuration,
PipelineSpec: NewPipelineSpec(j.PipelineSpec),
ExternalJobID: j.ExternalJobID,
}
switch j.Type {
case job.VRF:
resource.VRFSpec = NewVRFSpec(j.VRFSpec)
case job.Webhook:
resource.WebhookSpec = NewWebhookSpec(j.WebhookSpec)
case job.Gateway:
resource.GatewaySpec = NewGatewaySpec(j.GatewaySpec)
case job.LegacyGasStationServer, job.LegacyGasStationSidecar:
// unsupported
}
jes := []JobError{}
for _, e := range j.JobSpecErrors {
jes = append(jes, NewJobError((e)))
}
resource.Errors = jes
return resource
}
// GetName implements the api2go EntityNamer interface
func (r JobResource) GetName() string {
return "jobs"
}