Skip to content

Commit

Permalink
Support enable/disable JDs via API (#14937)
Browse files Browse the repository at this point in the history
* feat: add enalble and disable feeds manager mutations

* fix: goimport

* fix: deletedAt->disabletAt
  • Loading branch information
ChrisAmora authored Oct 27, 2024
1 parent 974def5 commit 3ad089f
Show file tree
Hide file tree
Showing 15 changed files with 754 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/good-chairs-boil.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": minor
---

#added Enable and Disable Feeds Manager mutations
3 changes: 3 additions & 0 deletions core/logger/audit/audit_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ const (
FeedsManCreated EventID = "FEEDS_MAN_CREATED"
FeedsManUpdated EventID = "FEEDS_MAN_UPDATED"

FeedsManEnabled EventID = "FEEDS_MAN_ENABLED"
FeedsManDisabled EventID = "FEEDS_MAN_DISABLED"

FeedsManChainConfigCreated EventID = "FEEDS_MAN_CHAIN_CONFIG_CREATED"
FeedsManChainConfigUpdated EventID = "FEEDS_MAN_CHAIN_CONFIG_UPDATED"
FeedsManChainConfigDeleted EventID = "FEEDS_MAN_CHAIN_CONFIG_DELETED"
Expand Down
118 changes: 118 additions & 0 deletions core/services/feeds/mocks/orm.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

118 changes: 118 additions & 0 deletions core/services/feeds/mocks/service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions core/services/feeds/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ type FeedsManager struct {
IsConnectionActive bool
CreatedAt time.Time
UpdatedAt time.Time
DisabledAt *time.Time
}

// ChainConfig defines the chain configuration for a Feeds Manager.
Expand Down
38 changes: 35 additions & 3 deletions core/services/feeds/orm.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ type ORM interface {
ListManagers(ctx context.Context) (mgrs []FeedsManager, err error)
ListManagersByIDs(ctx context.Context, ids []int64) ([]FeedsManager, error)
UpdateManager(ctx context.Context, mgr FeedsManager) error
EnableManager(ctx context.Context, id int64) (*FeedsManager, error)
DisableManager(ctx context.Context, id int64) (*FeedsManager, error)

CreateBatchChainConfig(ctx context.Context, cfgs []ChainConfig) ([]int64, error)
CreateChainConfig(ctx context.Context, cfg ChainConfig) (int64, error)
Expand Down Expand Up @@ -268,7 +270,7 @@ RETURNING id;
// GetManager gets a feeds manager by id.
func (o *orm) GetManager(ctx context.Context, id int64) (mgr *FeedsManager, err error) {
stmt := `
SELECT id, name, uri, public_key, created_at, updated_at
SELECT id, name, uri, public_key, created_at, updated_at, disabled_at
FROM feeds_managers
WHERE id = $1
`
Expand All @@ -281,7 +283,7 @@ WHERE id = $1
// ListManager lists all feeds managers.
func (o *orm) ListManagers(ctx context.Context) (mgrs []FeedsManager, err error) {
stmt := `
SELECT id, name, uri, public_key, created_at, updated_at
SELECT id, name, uri, public_key, created_at, updated_at, disabled_at
FROM feeds_managers
ORDER BY created_at;
`
Expand All @@ -293,7 +295,7 @@ ORDER BY created_at;
// ListManagersByIDs gets feeds managers by ids.
func (o *orm) ListManagersByIDs(ctx context.Context, ids []int64) (managers []FeedsManager, err error) {
stmt := `
SELECT id, name, uri, public_key, created_at, updated_at
SELECT id, name, uri, public_key, created_at, updated_at, disabled_at
FROM feeds_managers
WHERE id = ANY($1)
ORDER BY created_at, id;`
Expand Down Expand Up @@ -326,6 +328,36 @@ WHERE id = $4;
return nil
}

func (o *orm) EnableManager(ctx context.Context, id int64) (*FeedsManager, error) {
stmt := `
UPDATE feeds_managers
SET disabled_at = NULL
WHERE id = $1
RETURNING *;
`
mgr := new(FeedsManager)
err := o.ds.GetContext(ctx, mgr, stmt, id)
if err != nil {
return nil, errors.Wrap(err, "EnableManager failed")
}
return mgr, nil
}

func (o *orm) DisableManager(ctx context.Context, id int64) (*FeedsManager, error) {
stmt := `
UPDATE feeds_managers
SET disabled_at = NOW()
WHERE id = $1
RETURNING *;
`
mgr := new(FeedsManager)
err := o.ds.GetContext(ctx, mgr, stmt, id)
if err != nil {
return nil, errors.Wrap(err, "DisableManager failed")
}
return mgr, nil
}

// CreateJobProposal creates a job proposal.
func (o *orm) CreateJobProposal(ctx context.Context, jp *JobProposal) (id int64, err error) {
stmt := `
Expand Down
Loading

0 comments on commit 3ad089f

Please sign in to comment.