Skip to content

Commit

Permalink
Rename tsUpdate to tsUpdateOnly to be more clear
Browse files Browse the repository at this point in the history
  • Loading branch information
jakeschuurmans committed Aug 8, 2024
1 parent e95b8d2 commit 53cb53e
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 20 deletions.
1 change: 1 addition & 0 deletions .mockery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ packages:
github.com/metal-toolbox/ctrl:
config:
fileName: "mock_{{.InterfaceName | firstLower}}.go"
dir: "."
inpackage: True
interfaces:
TaskHandler:
Expand Down
6 changes: 3 additions & 3 deletions controller_nats.go
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,8 @@ func (n *NatsController) runTaskHandlerWithMonitor(ctx context.Context, task *co
defer span.End()

// local publish helper method
publish := func(state condition.State, status string, tsUpdate bool) {
if !tsUpdate {
publish := func(state condition.State, status string, tsUpdateOnly bool) {
if !tsUpdateOnly {
// append to existing status record, unless it was overwritten by the controller somehow
task.Status.Append(status)
task.State = state
Expand All @@ -555,7 +555,7 @@ func (n *NatsController) runTaskHandlerWithMonitor(ctx context.Context, task *co
if errPublish := publisher.Publish(
ctx,
task,
tsUpdate,
tsUpdateOnly,
); errPublish != nil {
n.logger.WithError(errPublish).Error("failed to publish update")
}
Expand Down
90 changes: 90 additions & 0 deletions mock_conditionStatusPublisher.go

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

16 changes: 8 additions & 8 deletions mock_publisher.go

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

14 changes: 7 additions & 7 deletions publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
//
// Subsequently the Task updates is all that is to be published, replacing the statusValue updates.
type Publisher interface {
Publish(ctx context.Context, task *condition.Task[any, any], tsUpdate bool) error
Publish(ctx context.Context, task *condition.Task[any, any], tsUpdateOnly bool) error
}

type PublisherHTTP struct {
Expand Down Expand Up @@ -55,14 +55,14 @@ func NewHTTPPublisher(serverID,
return p
}

func (p *PublisherHTTP) Publish(ctx context.Context, task *condition.Task[any, any], tsUpdate bool) error {
err := p.statusValuePublisher.Publish(ctx, task.Server.ID, task.State, task.Status.MustMarshal(), tsUpdate)
func (p *PublisherHTTP) Publish(ctx context.Context, task *condition.Task[any, any], tsUpdateOnly bool) error {
err := p.statusValuePublisher.Publish(ctx, task.Server.ID, task.State, task.Status.MustMarshal(), tsUpdateOnly)
if err != nil {
p.logger.WithError(err).Error("Status Value publish error")
return err
}

err = p.taskRepository.Publish(ctx, task, tsUpdate)
err = p.taskRepository.Publish(ctx, task, tsUpdateOnly)
if err != nil {
p.logger.WithError(err).Error("Task publish error")
return err
Expand Down Expand Up @@ -124,14 +124,14 @@ func NewNatsPublisher(
return p, nil
}

func (p *PublisherNATS) Publish(ctx context.Context, task *condition.Task[any, any], tsUpdate bool) error {
err := p.statusValuePublisher.Publish(ctx, task.Server.ID, task.State, task.Status.MustMarshal(), tsUpdate)
func (p *PublisherNATS) Publish(ctx context.Context, task *condition.Task[any, any], tsUpdateOnly bool) error {
err := p.statusValuePublisher.Publish(ctx, task.Server.ID, task.State, task.Status.MustMarshal(), tsUpdateOnly)
if err != nil {
p.logger.WithError(err).Error("Status Value publish error")
return err
}

err = p.taskRepository.Publish(ctx, task, tsUpdate)
err = p.taskRepository.Publish(ctx, task, tsUpdateOnly)
if err != nil {
p.logger.WithError(err).Error("Task publish error")
return err
Expand Down
4 changes: 2 additions & 2 deletions status.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (s *NatsConditionStatusPublisher) Publish(ctx context.Context, serverID str
return nil
}

func (s *NatsConditionStatusPublisher) update(key string, newStatusValue *condition.StatusValue, onlyTimestamp bool) (uint64, error) {
func (s *NatsConditionStatusPublisher) update(key string, newStatusValue *condition.StatusValue, tsUpdateOnly bool) (uint64, error) {
// fetch current status value from KV
entry, err := s.kv.Get(key)
if err != nil {
Expand All @@ -183,7 +183,7 @@ func (s *NatsConditionStatusPublisher) update(key string, newStatusValue *condit
}

var update *condition.StatusValue
if onlyTimestamp {
if tsUpdateOnly {
// timestamp only update
curStatusValue.UpdatedAt = time.Now()
update = curStatusValue
Expand Down

0 comments on commit 53cb53e

Please sign in to comment.