From 3d5d44aed00ac3c2c7f6dd4f755032bcd3d7f733 Mon Sep 17 00:00:00 2001 From: george-dorin <120329946+george-dorin@users.noreply.github.com> Date: Thu, 24 Aug 2023 16:58:29 +0300 Subject: [PATCH] Show jobs when a chain id disabled (#9948) * Combine errors * Fix lint * Show job spec if chain is disabled * Add test * Change to ErrNoSuchChainID --- core/services/job/orm.go | 5 +- core/web/resolver/job_test.go | 88 ++++++++++++++++++++++++----------- core/web/resolver/query.go | 4 ++ 3 files changed, 66 insertions(+), 31 deletions(-) diff --git a/core/services/job/orm.go b/core/services/job/orm.go index 342623a62be..d7cfbd0fc4a 100644 --- a/core/services/job/orm.go +++ b/core/services/job/orm.go @@ -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 }) diff --git a/core/web/resolver/job_test.go b/core/web/resolver/job_test.go index 8a34b5a4ffc..7d73d7d0d2a 100644 --- a/core/web/resolver/job_test.go +++ b/core/web/resolver/job_test.go @@ -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" @@ -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{ @@ -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", @@ -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) diff --git a/core/web/resolver/query.go b/core/web/resolver/query.go index 05a778a6624..22b95a2d2ef 100644 --- a/core/web/resolver/query.go +++ b/core/web/resolver/query.go @@ -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