Skip to content

Commit

Permalink
consistent nameing (feedback)
Browse files Browse the repository at this point in the history
  • Loading branch information
wass3rw3rk committed Jun 20, 2024
1 parent 7699745 commit 924390d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
16 changes: 8 additions & 8 deletions api/build/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ import (
// without execution. This will kill all resources,
// like steps and services, for the build.
func CleanBuild(ctx context.Context, database database.Interface, b *types.Build, services []*library.Service, steps []*library.Step, e error) {
logger := logrus.WithFields(logrus.Fields{
l := logrus.WithFields(logrus.Fields{
"build": b.GetNumber(),
"build_id": b.GetID(),
"org": b.GetRepo().GetOrg(),
"repo": b.GetRepo().GetName(),
"repo_id": b.GetRepo().GetID(),
})

logger.Debug("cleaning build")
l.Debug("cleaning build")

// update fields in build object
b.SetError(fmt.Sprintf("unable to publish to queue: %s", e.Error()))
Expand All @@ -37,10 +37,10 @@ func CleanBuild(ctx context.Context, database database.Interface, b *types.Build
// send API call to update the build
b, err := database.UpdateBuild(ctx, b)
if err != nil {
logger.Errorf("unable to kill build %d: %v", b.GetNumber(), err)
l.Errorf("unable to kill build %d: %v", b.GetNumber(), err)
}

logger.Info("build updated - build cleaned")
l.Info("build updated - build cleaned")

for _, s := range services {
// update fields in service object
Expand All @@ -50,10 +50,10 @@ func CleanBuild(ctx context.Context, database database.Interface, b *types.Build
// send API call to update the service
_, err := database.UpdateService(ctx, s)
if err != nil {
logger.Errorf("unable to kill service %s for build %d: %v", s.GetName(), b.GetNumber(), err)
l.Errorf("unable to kill service %s for build %d: %v", s.GetName(), b.GetNumber(), err)
}

logger.WithFields(logrus.Fields{
l.WithFields(logrus.Fields{
"service": s.GetName(),
"service_id": s.GetID(),
}).Info("service updated - service cleaned")
Expand All @@ -67,10 +67,10 @@ func CleanBuild(ctx context.Context, database database.Interface, b *types.Build
// send API call to update the step
_, err := database.UpdateStep(ctx, s)
if err != nil {
logger.Errorf("unable to kill step %s for build %d: %v", s.GetName(), b.GetNumber(), err)
l.Errorf("unable to kill step %s for build %d: %v", s.GetName(), b.GetNumber(), err)
}

logger.WithFields(logrus.Fields{
l.WithFields(logrus.Fields{
"step": s.GetName(),
"step_id": s.GetID(),
}).Info("step updated - step cleaned")
Expand Down
16 changes: 8 additions & 8 deletions api/build/enqueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,36 @@ import (

// Enqueue is a helper function that pushes a queue item (build, repo, user) to the queue.
func Enqueue(ctx context.Context, queue queue.Service, db database.Interface, item *models.Item, route string) {
logger := logrus.WithFields(logrus.Fields{
l := logrus.WithFields(logrus.Fields{
"build": item.Build.GetNumber(),
"build_id": item.Build.GetID(),
"org": item.Build.GetRepo().GetOrg(),
"repo": item.Build.GetRepo().GetName(),
"repo_id": item.Build.GetRepo().GetID(),
})

logger.Debug("converting queue item to json")
l.Debug("converting queue item to json")

byteItem, err := json.Marshal(item)
if err != nil {
logger.Errorf("failed to convert item to json: %v", err)
l.Errorf("failed to convert item to json: %v", err)

// error out the build
CleanBuild(ctx, db, item.Build, nil, nil, err)

return
}

logger.Debugf("pushing item for build to queue route %s", route)
l.Debugf("pushing item for build to queue route %s", route)

// push item on to the queue
err = queue.Push(context.Background(), route, byteItem)
if err != nil {
logger.Errorf("retrying; failed to publish build: %v", err)
l.Errorf("retrying; failed to publish build: %v", err)

err = queue.Push(context.Background(), route, byteItem)
if err != nil {
logger.Errorf("failed to publish build: %v", err)
l.Errorf("failed to publish build: %v", err)

// error out the build
CleanBuild(ctx, db, item.Build, nil, nil, err)
Expand All @@ -60,8 +60,8 @@ func Enqueue(ctx context.Context, queue queue.Service, db database.Interface, it
// update the build in the db to reflect the time it was enqueued
_, err = db.UpdateBuild(ctx, item.Build)
if err != nil {
logger.Errorf("failed to update build during publish to queue: %v", err)
l.Errorf("failed to update build during publish to queue: %v", err)
}

logger.Info("updated build as enqueued")
l.Info("updated build as enqueued")
}

0 comments on commit 924390d

Please sign in to comment.