Skip to content

Commit

Permalink
small fixes for pipelines (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmoghaddam385 authored May 17, 2021
1 parent 26bffc0 commit 80529c3
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 14 deletions.
7 changes: 4 additions & 3 deletions errand-routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"errors"
"fmt"
"net/http"

gin "github.com/gin-gonic/gin"
Expand Down Expand Up @@ -88,7 +89,7 @@ func (s *ErrandsServer) failedErrand(c *gin.Context) {
return err
}
errand.Failed = utils.GetTimestamp()
errand.Status = "failed"
errand.Status = schemas.StatusFailed
errand.Progress = 0
if errand.Options.Retries > 0 {
// If we should retry this errand:
Expand Down Expand Up @@ -148,7 +149,7 @@ func (s *ErrandsServer) completeErrand(c *gin.Context) {
return err
}
errand.Completed = utils.GetTimestamp()
errand.Status = "completed"
errand.Status = schemas.StatusCompleted
errand.Progress = 100
// errand.Results = compReq.Results
// If we should delete this errand upon completion:
Expand Down Expand Up @@ -263,7 +264,7 @@ func (s *ErrandsServer) UpdateErrandByID(id string, fn func(*schemas.Errand) err

errand := errandObj.(schemas.Errand)
if err := fn(&errand); err != nil {
return nil, errors.New("error in given update function (fn)")
return nil, fmt.Errorf("error in given update function (fn): %w", err)
}

s.updateErrandInPipeline(&errand)
Expand Down
23 changes: 13 additions & 10 deletions errands-routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,18 +223,21 @@ func (s *ErrandsServer) processErrand(c *gin.Context) {

procErrand = errands[0]

// We are processing this errand:
procErrand.Started = utils.GetTimestamp()
procErrand.Attempts += 1
procErrand.Status = "active"
procErrand.Progress = 0.0
_ = procErrand.AddToLogs("INFO", "Started!")
_ = s.saveErrand(&procErrand)

s.AddNotification("processing", &procErrand)
// We are processing this errand. This won't ever return error
updatedErrand, _ := s.UpdateErrandByID(procErrand.ID, func(errand *schemas.Errand) error {
errand.Started = utils.GetTimestamp()
errand.Attempts++
errand.Status = schemas.StatusActive
errand.Progress = 0.0

_ = errand.AddToLogs("INFO", "Started!")
return nil
})

s.AddNotification("processing", updatedErrand)
c.JSON(http.StatusOK, gin.H{
"status": "OK",
"results": procErrand,
"results": updatedErrand,
})
}

Expand Down
2 changes: 2 additions & 0 deletions errands-server.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,14 @@ func NewErrandsServer(cfg *Config) *ErrandsServer {
go obj.broadcastLoop()

if err := obj.ErrandStore.LoadFile(path.Join(cfg.Storage, errandsDBPathSuffix)); err != nil {
log.WithError(err).Error("unable to load errands db")
log.Warning("Could not load errand data from previous DB file.")
log.Warning("If this is your first time running, this is normal.")
log.Warning("If not please check the contents of your file: ", cfg.Storage)
}

if err := obj.ErrandStore.LoadFile(path.Join(cfg.Storage, pipelinesDBPathSuffix)); err != nil {
log.WithError(err).Error("unable to load pipelines db")
log.Warning("Could not load pipeline data from previous DB file.")
log.Warning("If this is your first time running, this is normal.")
log.Warning("If not please check the contents of your file: ", cfg.Storage)
Expand Down
1 change: 1 addition & 0 deletions pipeline-routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func (s *ErrandsServer) createPipeline(c *gin.Context) {
// Initialize all the errands in the pipeline
for _, errand := range pipeline.Errands {
errand.SetDefaults()
errand.PipelineID = pipeline.ID
errand.Status = schemas.StatusBlocked

if err := s.saveErrand(errand); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion schemas/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (p *Pipeline) RecalculateStatus() {
p.Status = StatusActive
}

if p.Status == StatusCompleted {
if errand.Status == StatusCompleted {
numCompleted++
}
}
Expand Down

0 comments on commit 80529c3

Please sign in to comment.