Skip to content

Commit

Permalink
Show jobs when a chain id disabled (smartcontractkit#9948)
Browse files Browse the repository at this point in the history
* Combine errors

* Fix lint

* Show job spec if chain is disabled

* Add test

* Change to ErrNoSuchChainID
  • Loading branch information
george-dorin authored Aug 24, 2023
1 parent 7d45261 commit 3d5d44a
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 31 deletions.
5 changes: 1 addition & 4 deletions core/services/job/orm.go
Original file line number Diff line number Diff line change
Expand Up @@ -684,10 +684,7 @@ func (o *orm) FindJobs(offset, limit int) (jobs []Job, count int, err error) {
return err
}
for i := range jobs {
err = o.LoadEnvConfigVars(&jobs[i])
if err != nil {
return err
}
err = multierr.Combine(err, o.LoadEnvConfigVars(&jobs[i]))
}
return nil
})
Expand Down
88 changes: 61 additions & 27 deletions core/web/resolver/job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/stretchr/testify/mock"
"gopkg.in/guregu/null.v4"

"github.com/smartcontractkit/chainlink/v2/core/chains"
clnull "github.com/smartcontractkit/chainlink/v2/core/null"
"github.com/smartcontractkit/chainlink/v2/core/services/directrequest"
"github.com/smartcontractkit/chainlink/v2/core/services/job"
Expand Down Expand Up @@ -171,6 +172,32 @@ func TestResolver_Job(t *testing.T) {
}
}
`
exampleJobResult = `
{
"job": {
"id": "1",
"createdAt": "2021-01-01T00:00:00Z",
"externalJobID": "00000000-0000-0000-0000-000000000001",
"gasLimit": 123,
"maxTaskDuration": "1s",
"name": "job1",
"schemaVersion": 1,
"spec": {
"__typename": "OCRSpec"
},
"runs": {
"__typename": "JobRunsPayload",
"results": [{
"id": "200"
}],
"metadata": {
"total": 1
}
},
"observationSource": "ds1 [type=bridge name=voter_turnout];"
}
}
`
)

testCases := []GQLTestCase{
Expand Down Expand Up @@ -204,33 +231,8 @@ func TestResolver_Job(t *testing.T) {
On("CountPipelineRunsByJobID", int32(1)).
Return(int32(1), nil)
},
query: query,
result: `
{
"job": {
"id": "1",
"createdAt": "2021-01-01T00:00:00Z",
"externalJobID": "00000000-0000-0000-0000-000000000001",
"gasLimit": 123,
"maxTaskDuration": "1s",
"name": "job1",
"schemaVersion": 1,
"spec": {
"__typename": "OCRSpec"
},
"runs": {
"__typename": "JobRunsPayload",
"results": [{
"id": "200"
}],
"metadata": {
"total": 1
}
},
"observationSource": "ds1 [type=bridge name=voter_turnout];"
}
}
`,
query: query,
result: exampleJobResult,
},
{
name: "not found",
Expand All @@ -249,6 +251,38 @@ func TestResolver_Job(t *testing.T) {
}
`,
},
{
name: "show job when chainID is disabled",
authenticated: true,
before: func(f *gqlTestFramework) {
f.App.On("JobORM").Return(f.Mocks.jobORM)
f.Mocks.jobORM.On("FindJobWithoutSpecErrors", id).Return(job.Job{
ID: 1,
Name: null.StringFrom("job1"),
SchemaVersion: 1,
GasLimit: clnull.Uint32From(123),
MaxTaskDuration: models.Interval(1 * time.Second),
ExternalJobID: externalJobID,
CreatedAt: f.Timestamp(),
Type: job.OffchainReporting,
OCROracleSpec: &job.OCROracleSpec{},
PipelineSpec: &pipeline.Spec{
DotDagSource: "ds1 [type=bridge name=voter_turnout];",
},
}, chains.ErrNoSuchChainID)
f.Mocks.jobORM.
On("FindPipelineRunIDsByJobID", int32(1), 0, 50).
Return([]int64{200}, nil)
f.Mocks.jobORM.
On("FindPipelineRunsByIDs", []int64{200}).
Return([]pipeline.Run{{ID: 200}}, nil)
f.Mocks.jobORM.
On("CountPipelineRunsByJobID", int32(1)).
Return(int32(1), nil)
},
query: query,
result: exampleJobResult,
},
}

RunGQLTests(t, testCases)
Expand Down
4 changes: 4 additions & 0 deletions core/web/resolver/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,11 @@ func (r *Resolver) Job(ctx context.Context, args struct{ ID graphql.ID }) (*JobP
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
return NewJobPayload(r.App, nil, err), nil
}

//We still need to show the job in UI/CLI even if the chain id is disabled
if errors.Is(err, chains.ErrNoSuchChainID) {
return NewJobPayload(r.App, &j, err), nil
}

return nil, err
Expand Down

0 comments on commit 3d5d44a

Please sign in to comment.