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

Commit job state change before running update hooks #11170

Merged

Conversation

dbnicholson
Copy link
Contributor

Summary

Without this, the state queried by job_storage will not match the updated state. This can cause a problem if a hook tries to restart a canceled job because job_storage will still see the state as CANCELING.

Fixes: #11169

References

#11169

This fixes the case I was seeing. Before:

[python-devserver] INFO     2023-08-28 16:22:58,428 Restarting incomplete BackgroundTask func: kolibri_explore_plugin.tasks.remotecontentimport, params: {"channel_id": "2f95235c3709511fa12d007f31ed6a7b", "channel_name": "STEAM", "node_ids": [], "exclude_node_ids": [], "all_thumbnails": true, "fail_on_error": true}, job_id: 3bce247d8c034ea0b694b87f6c2e292c, job_state: CANCELED
[python-devserver] ERROR    2023-08-28 16:22:58,429 exception calling callback for <Future at 0x7f824032a670 state=finished raised JobNotRestartable>

With this change, the job is queued and the server shuts down cleanly.

Reviewer guidance

See the description in #11169. Unfortunately, testing the job worker + StorageHook is not easy.


Testing checklist

  • Contributor has fully tested the PR manually
  • If there are any front-end changes, before/after screenshots are included
  • Critical user journeys are covered by Gherkin stories
  • Critical and brittle code paths are covered by unit tests

PR process

  • PR has the correct target branch and milestone
  • PR has 'needs review' or 'work-in-progress' label
  • If PR is ready for review, a reviewer has been added. (Don't use 'Assignees')
  • If this is an important user-facing change, PR or related issue has a 'changelog' label
  • If this includes an internal dependency change, a link to the diff is provided

Reviewer checklist

  • Automated test coverage is satisfactory
  • PR is fully functional
  • PR has been tested for accessibility regressions
  • External dependency files were updated if necessary (yarn and pip)
  • Documentation is updated
  • Contributor is in AUTHORS.md

Without this, the state queried by `job_storage` will not match the
updated state. This can cause a problem if a hook tries to restart a
canceled job because `job_storage` will still see the state as
`CANCELING`.

Fixes: learningequality#11169
@MisRob MisRob added the TODO: needs review Waiting for review label Aug 29, 2023
Copy link
Member

@rtibbles rtibbles left a comment

Choose a reason for hiding this comment

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

I double checked how the hooks are being used in the Android App, and I don't think this should cause any issues. Worth noting that the use case here (manipulating job state within the hooks) was not the original intention of this hook, but I can see why it is useful in this case.

@rtibbles rtibbles merged commit afcb2cf into learningequality:release-v0.16.x Aug 30, 2023
@dbnicholson dbnicholson deleted the task-update-commit branch August 30, 2023 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DEV: backend Python, databases, networking, filesystem... SIZE: very small TODO: needs review Waiting for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Task update hook run before state update committed
3 participants