Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(worker): work with booked job #3397

Merged
merged 3 commits into from
Oct 4, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 28 additions & 22 deletions engine/worker/cmd_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,28 +118,6 @@ func runCmd(w *currentWorker) func(cmd *cobra.Command, args []string) {
if !w.disableOldWorkflows && w.bookedPBJobID != 0 {
w.processBookedPBJob(pbjobs)
}
var exceptJobID int64
if w.bookedWJobID != 0 {
if errP := w.processBookedWJob(wjobs); errP != nil {
// Unbook job
if errR := w.client.QueueJobRelease(true, w.bookedWJobID); errR != nil {
log.Error("runCmd> QueueJobRelease> Cannot release job")
}
exceptJobID = w.bookedWJobID
w.bookedWJobID = 0
} else {
exceptJobID = w.bookedWJobID
}
}
if err := w.client.WorkerSetStatus(sdk.StatusWaiting); err != nil {
log.Error("WorkerSetStatus> error on WorkerSetStatus(sdk.StatusWaiting): %s", err)
}

go func(ctx context.Context, exceptID *int64) {
if err := w.client.QueuePolling(ctx, wjobs, pbjobs, errs, 2*time.Second, 0, "", nil, exceptID); err != nil {
log.Info("Queues polling stopped: %v", err)
}
}(ctx, &exceptJobID)

//Definition of the function which must be called to stop the worker
var endFunc = func() {
Expand Down Expand Up @@ -169,6 +147,34 @@ func runCmd(w *currentWorker) func(cmd *cobra.Command, args []string) {
}
}

var exceptJobID int64
if w.bookedWJobID != 0 {
if errP := w.processBookedWJob(wjobs); errP != nil {
// Unbook job
if errR := w.client.QueueJobRelease(true, w.bookedWJobID); errR != nil {
log.Error("runCmd> QueueJobRelease> Cannot release job")
}
exceptJobID = w.bookedWJobID
w.bookedWJobID = 0
// this worker was spawned for a job
// this job can't be process (errP != nil)
// so, call endFunc() now, this worker don't have to work
// on another job
endFunc()
return
}
exceptJobID = w.bookedWJobID
}
if err := w.client.WorkerSetStatus(sdk.StatusWaiting); err != nil {
log.Error("WorkerSetStatus> error on WorkerSetStatus(sdk.StatusWaiting): %s", err)
}

go func(ctx context.Context, exceptID *int64) {
if err := w.client.QueuePolling(ctx, wjobs, pbjobs, errs, 2*time.Second, 0, "", nil, exceptID); err != nil {
log.Info("Queues polling stopped: %v", err)
}
}(ctx, &exceptJobID)

// Errors check loops
go func(errs chan error) {
for {
Expand Down
6 changes: 5 additions & 1 deletion engine/worker/take_workflow_node_run_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ import (
func (w *currentWorker) takeWorkflowJob(ctx context.Context, job sdk.WorkflowNodeJobRun) (bool, error) {
info, err := w.client.QueueTakeJob(job, w.bookedWJobID == job.ID)
if err != nil {
return true, sdk.WrapError(err, "takeWorkflowJob> Unable to take workflow node run job. This worker can work on another job.")
if w.bookedWJobID == job.ID {
return false, sdk.WrapError(err, "takeWorkflowJob> Unable to take workflow node run job. This worker can't work on another job.")
} else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove else

return true, sdk.WrapError(err, "takeWorkflowJob> Unable to take workflow node run job. This worker can work on another job.")
}
}
t := ""
if w.bookedWJobID == job.ID {
Expand Down