Skip to content

Commit

Permalink
fix(worker): stop the worker
Browse files Browse the repository at this point in the history
  • Loading branch information
fsamin committed Jan 19, 2020
1 parent bf49500 commit cd10319
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
6 changes: 5 additions & 1 deletion engine/hatchery/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,13 @@ func (h *HatcheryLocal) ApplyConfiguration(cfg interface{}) error {
genname := h.Configuration().Name
h.Common.Common.ServiceName = genname
h.Common.Common.ServiceType = services.TypeHatchery
var err error
h.Config.Basedir, err = filepath.Abs(h.Config.Basedir)
if err != nil {
return fmt.Errorf("unable to get basedir absolute path: %v", err)
}
h.HTTPURL = h.Config.URL
h.MaxHeartbeatFailures = h.Config.API.MaxHeartbeatFailures
var err error
h.Common.Common.PrivateKey, err = jwt.ParseRSAPrivateKeyFromPEM([]byte(h.Config.RSAPrivateKey))
if err != nil {
return fmt.Errorf("unable to parse RSA private Key: %v", err)
Expand Down
4 changes: 3 additions & 1 deletion engine/worker/internal/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ func (wk *CurrentWorker) sendHTTPLog(ctx context.Context, jobID int64) {

for _, l := range logs {
log.Debug("LOG: %v", l.Val)
if err := wk.Client().QueueSendLogs(wk.currentJob.context, jobID, *l); err != nil {
// TODO: stop the worker a nice way,
// for the moment we are using context.Background and not the job context
if err := wk.Client().QueueSendLogs(context.Background(), jobID, *l); err != nil {
log.Error(ctx, "error: cannot send logs: %s", err)
continue
}
Expand Down
3 changes: 2 additions & 1 deletion engine/worker/internal/take.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ func (w *CurrentWorker) Take(ctx context.Context, job sdk.WorkflowNodeJobRun) er
t := ""
log.Info(ctx, "takeWorkflowJob> Job %d taken%s", job.ID, t)

ctx, cancel := context.WithCancel(ctx)

w.currentJob.context = workerruntime.SetJobID(ctx, job.ID)
w.currentJob.context = ctx

Expand All @@ -32,7 +34,6 @@ func (w *CurrentWorker) Take(ctx context.Context, job sdk.WorkflowNodeJobRun) er
start := time.Now()

//This goroutine try to get the job every 5 seconds, if it fails, it cancel the build.
ctx, cancel := context.WithCancel(ctx)
tick := time.NewTicker(5 * time.Second)
go func(cancel context.CancelFunc, jobID int64, tick *time.Ticker) {
var nbConnrefused int
Expand Down
1 change: 1 addition & 0 deletions tools/smtpmock/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
server/server

0 comments on commit cd10319

Please sign in to comment.