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(job): fetch parent before job moves to complete #1580

Merged
merged 5 commits into from Dec 20, 2022

Conversation

S3bb1
Copy link
Contributor

@S3bb1 S3bb1 commented Dec 9, 2022

When creating a flow with a long-running job in the beginning (e.g. takes multiple seconds) and during the processing of the job you want to add a new parent to this job (because it should run after the long-running job) it doesn't execute the job which was added after.

The root cause of this issue is, that the worker fetches the Job from redis before it moves it to active. When the Job then finishes, the worker passes the previous fetched instance of the job to moveToCompleted. When an additional Job is added as parent of the current processing job, it never gets executed because the instance doesn't have the correct parent key.

This PR adds an additional "sync" of the parent key of the job before it gets moved to completed to have the current instance up to date when in the meantime a new parent was added.

Added a test which runs the following flow:

  • Create Job 1 without children
    • Flow moves Job to active
    • Worker processes job (wait 1000ms)
  • Client waits 500ms
  • Client adds new Job 2 with children [Job1]
  • Worker finishes Job 1
  • Worker starts Job 2
  • Worker finishes Job 2

@@ -516,6 +516,11 @@ export class Job<
throw errorObject.value;
}

const jobData = await Job.fromId(this.queue, this.id);
Copy link
Collaborator

Choose a reason for hiding this comment

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

better to handle this logic atomically in moveToFinished script, so probably we may need to get parent values from there instead of providing it in args

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the fetch of the parent and the parentKey into the lua scripts.

@S3bb1
Copy link
Contributor Author

S3bb1 commented Dec 15, 2022

Can we rerun the tests? On my local machine they went through

@S3bb1
Copy link
Contributor Author

S3bb1 commented Dec 20, 2022

Any updates here @roggervalf?

Copy link
Collaborator

@roggervalf roggervalf left a comment

Choose a reason for hiding this comment

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

Sorry for the delay, LGTM

@roggervalf roggervalf merged commit 6a6c0dc into taskforcesh:master Dec 20, 2022
github-actions bot pushed a commit that referenced this pull request Dec 20, 2022
# [3.5.0](v3.4.2...v3.5.0) (2022-12-20)

### Bug Fixes

* **job:** fetch parent before job moves to complete ([#1580](#1580)) ([6a6c0dc](6a6c0dc))
* **sandbox:** throw error when no exported function ([#1588](#1588)) fixes [#1587](#1587) ([c031891](c031891))

### Features

* **queue:** add getJobState method ([#1593](#1593)) ref [#1532](#1532) ([b741e84](b741e84))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants