Skip to content

Commit

Permalink
service: minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ilgooz committed Sep 4, 2018
1 parent c2c1042 commit 08ddceb
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 20 deletions.
18 changes: 7 additions & 11 deletions api/deploy_deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,14 @@ func (d *serviceDeployer) sendStatus(message string, typ StatusType) {
// forwardStatuses forwards status messages.
func (d *serviceDeployer) forwardDeployStatuses(statuses chan service.DeployStatus) {
for status := range statuses {
if d.statuses != nil {
st := DeployStatus{
Message: status.Message,
}
switch status.Type {
case service.DRUNNING:
st.Type = RUNNING
case service.DDONE:
st.Type = DONE
}
d.statuses <- st
var t StatusType
switch status.Type {
case service.DRUNNING:
t = RUNNING
case service.DDONE:
t = DONE
}
d.sendStatus(status.Message, t)
}
}

Expand Down
3 changes: 1 addition & 2 deletions api/get_getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,5 @@ func (g *serviceGetter) Get(serviceID string) (*service.Service, error) {
if err != nil {
return nil, err
}
s, err = service.FromService(s, service.ContainerOption(g.api.container))
return s, err
return service.FromService(s, service.ContainerOption(g.api.container))
}
8 changes: 4 additions & 4 deletions service/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ package service
// Event describes a service task.
type Event struct {
// Key is the key of event.
Key string `hash:"-"`
Key string `hash:"1"`

// Name is the name of event.
Name string `hash:"name:1"`
Name string `hash:"name:2"`

// Description is the description of event.
Description string `hash:"name:2"`
Description string `hash:"name:3"`

// Data holds the input parameters of event.
Data []*Parameter `hash:"name:3"`
Data []*Parameter `hash:"name:4"`

// service is the event's service.
service *Service `hash:"-"`
Expand Down
10 changes: 7 additions & 3 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func New(tarball io.Reader, options ...Option) (*Service, error) {

def, err := importer.From(s.tempPath)
if err != nil {
os.RemoveAll(s.tempPath)
s.removeTempDir()
return nil, err
}
s.injectDefinition(def)
Expand All @@ -109,7 +109,7 @@ func New(tarball io.Reader, options ...Option) (*Service, error) {
return s.fromService(), nil
}

// FromService upgrades service s to by setting its options and private fields.
// FromService upgrades service s by setting its options and private fields.
func FromService(s *Service, options ...Option) (*Service, error) {
if err := s.setOptions(options...); err != nil {
return nil, err
Expand Down Expand Up @@ -192,9 +192,13 @@ func (s *Service) createTempDir() (path string, err error) {
return ioutil.TempDir("", "mesg-"+uuid.NewV4().String())
}

func (s *Service) removeTempDir() error {
return os.RemoveAll(s.tempPath)
}

// deploy deploys service.
func (s *Service) deploy() error {
defer os.RemoveAll(s.tempPath)
defer s.removeTempDir()
defer s.closeStatusSend()

s.sendStatus("Building Docker image...", DRUNNING)
Expand Down

0 comments on commit 08ddceb

Please sign in to comment.