Skip to content

Commit

Permalink
Minimal refactor and cosmetic changes based on feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jordigilh committed Aug 11, 2022
1 parent 5160940 commit 72763f8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
8 changes: 6 additions & 2 deletions internal/service/event_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,23 @@ func translateUnitSubStatus(unit *dbus.UnitStatus) unitSubState {
}

func (e *EventListener) Add(workloadName string) {
name := fmt.Sprintf("%s.service", workloadName)
name := formatServiceName(workloadName)
log.Debugf("Adding service for events %s", name)
if !e.set.Contains(name) {
e.set.Add(name)
}
}

func (e *EventListener) Remove(workloadName string) {
name := fmt.Sprintf("%s.service", workloadName)
name := formatServiceName(workloadName)
log.Debugf("Removing service for events %s", name)
e.set.Remove(name)
}

func extractWorkloadName(serviceName string) string {
return serviceName[:len(serviceName)-servicePostfixLength]
}

func formatServiceName(workloadName string) string {
return fmt.Sprintf("%s.service", workloadName)
}
1 change: 0 additions & 1 deletion internal/service/systemd.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const (
DefaultRestartTimeout = 15
TimerSuffix = ".timer"
ServiceSuffix = ".service"
DefaultNameSeparator = "-"
)

var (
Expand Down
4 changes: 2 additions & 2 deletions internal/workload/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,9 @@ func (ww *Workload) removeService(workloadName string) error {
return fmt.Errorf("Cannot remove systemd service for '%s': %s", workloadName, err)
}

err = ww.serviceManager.Remove(svc)
err := ww.serviceManager.Remove(svc)
if err != nil {
log.Errorf("unable to remove service from serviceManager %s:%s", workloadName, err)
log.Errorf("Unable to remove service from serviceManager %s:%s", workloadName, err)
}
return nil
}
Expand Down

0 comments on commit 72763f8

Please sign in to comment.