Skip to content

Commit

Permalink
constify msg variables
Browse files Browse the repository at this point in the history
These are never re-assigned to so there's no real reason to define as an
empty string and later updated a couple lines below. After that clean up
there's no reason not to make it a `const`. Having it `const` helps to
convey that its never meant to be updated.

Signed-off-by: Manuel Mendez <[email protected]>
  • Loading branch information
mmlb committed Sep 8, 2020
1 parent 6d4462c commit ce59e89
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 19 deletions.
5 changes: 2 additions & 3 deletions grpc-server/hardware.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,13 @@ func (s *server) Push(ctx context.Context, in *hardware.PushRequest) (*hardware.
}

var fn func() error
msg := ""
const msg = "inserting into DB"
data, err := json.Marshal(hw)
if err != nil {
logger.Error(err)
}

labels["op"] = "insert"
msg = "inserting into DB"
fn = func() error { return s.db.InsertIntoDB(ctx, string(data)) }

metrics.CacheTotals.With(labels).Inc()
Expand Down Expand Up @@ -263,7 +262,7 @@ func (s *server) Delete(ctx context.Context, in *hardware.DeleteRequest) (*hardw

var fn func() error
labels["op"] = "delete"
msg := "deleting into DB"
const msg = "deleting into DB"
fn = func() error { return s.db.DeleteFromDB(ctx, in.Id) }

metrics.CacheTotals.With(labels).Inc()
Expand Down
12 changes: 4 additions & 8 deletions grpc-server/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ func (s *server) CreateTemplate(ctx context.Context, in *template.WorkflowTempla
metrics.CacheInFlight.With(labels).Inc()
defer metrics.CacheInFlight.With(labels).Dec()

msg := ""
const msg = "creating a new Template"
labels["op"] = "createtemplate"
msg = "creating a new Template"
id := uuid.NewV4()
fn := func() error { return s.db.CreateTemplate(ctx, in.Name, in.Data, id) }

Expand Down Expand Up @@ -51,9 +50,8 @@ func (s *server) GetTemplate(ctx context.Context, in *template.GetRequest) (*tem
metrics.CacheInFlight.With(labels).Inc()
defer metrics.CacheInFlight.With(labels).Dec()

msg := ""
const msg = "getting a template"
labels["op"] = "get"
msg = "getting a template"

fn := func() (string, string, error) { return s.db.GetTemplate(ctx, in.Id) }
metrics.CacheTotals.With(labels).Inc()
Expand Down Expand Up @@ -81,9 +79,8 @@ func (s *server) DeleteTemplate(ctx context.Context, in *template.GetRequest) (*
metrics.CacheInFlight.With(labels).Inc()
defer metrics.CacheInFlight.With(labels).Dec()

msg := ""
const msg = "deleting a template"
labels["op"] = "delete"
msg = "deleting a template"
fn := func() error { return s.db.DeleteTemplate(ctx, in.Id) }

metrics.CacheTotals.With(labels).Inc()
Expand Down Expand Up @@ -142,9 +139,8 @@ func (s *server) UpdateTemplate(ctx context.Context, in *template.WorkflowTempla
metrics.CacheInFlight.With(labels).Inc()
defer metrics.CacheInFlight.With(labels).Dec()

msg := ""
const msg = "updating a template"
labels["op"] = "updatetemplate"
msg = "updating a template"
fn := func() error { return s.db.UpdateTemplate(ctx, in.Name, in.Data, uuid.FromStringOrNil(in.Id)) }

metrics.CacheTotals.With(labels).Inc()
Expand Down
13 changes: 5 additions & 8 deletions grpc-server/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ func (s *server) CreateWorkflow(ctx context.Context, in *workflow.CreateRequest)
labels := prometheus.Labels{"method": "CreateWorkflow", "op": ""}
metrics.CacheInFlight.With(labels).Inc()
defer metrics.CacheInFlight.With(labels).Dec()
msg := ""

const msg = "creating a new workflow"
labels["op"] = "createworkflow"
msg = "creating a new workflow"
id := uuid.NewV4()
fn := func() error {
wf := db.Workflow{
Expand Down Expand Up @@ -79,9 +79,8 @@ func (s *server) GetWorkflow(ctx context.Context, in *workflow.GetRequest) (*wor
metrics.CacheInFlight.With(labels).Inc()
defer metrics.CacheInFlight.With(labels).Dec()

msg := ""
const msg = "getting a workflow"
labels["op"] = "get"
msg = "getting a workflow"

fn := func() (db.Workflow, error) { return s.db.GetWorkflow(ctx, in.Id) }
metrics.CacheTotals.With(labels).Inc()
Expand Down Expand Up @@ -121,10 +120,9 @@ func (s *server) DeleteWorkflow(ctx context.Context, in *workflow.GetRequest) (*
metrics.CacheInFlight.With(labels).Inc()
defer metrics.CacheInFlight.With(labels).Dec()

msg := ""
const msg = "deleting a workflow"
labels["op"] = "delete"
l := logger.With("workflowID", in.GetId())
msg = "deleting a workflow"
fn := func() error {
// update only if not in running state
return s.db.DeleteWorkflow(ctx, in.Id, workflow.State_value[workflow.State_RUNNING.String()])
Expand Down Expand Up @@ -192,9 +190,8 @@ func (s *server) GetWorkflowContext(ctx context.Context, in *workflow.GetRequest
metrics.CacheInFlight.With(labels).Inc()
defer metrics.CacheInFlight.With(labels).Dec()

msg := ""
const msg = "getting a workflow"
labels["op"] = "get"
msg = "getting a workflow"

fn := func() (*workflowpb.WorkflowContext, error) { return s.db.GetWorkflowContexts(ctx, in.Id) }
metrics.CacheTotals.With(labels).Inc()
Expand Down

0 comments on commit ce59e89

Please sign in to comment.