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

Refactor/task builder #131

Merged
merged 48 commits into from
Mar 27, 2021
Merged

Conversation

JonatanMartens
Copy link
Collaborator

@JonatanMartens JonatanMartens commented Feb 27, 2021

Move the task building process from ZeebeWorker.
This pr introduces a breaking change.

Changes

  • Add TaskConfig class, which is used internally
  • Remove TaskHandler class
  • Remove ZeebeTaskDecorator base class
    • ZeebeWorker now inherits from ZeebeTaskRouter

API Updates

none

Enhancements (optional)

Move task building functionality out of the ZeebeWorker class.

Checklist

  • Unit tests
  • Documentation

@JonatanMartens
Copy link
Collaborator Author

Considering this is a breaking change, I think it is a good idea to include zeebe v1.0.0 support before releasing. See https://forum.zeebe.io/t/changelog-for-zeebe-client-lib-maintainers/2064

@kbakk kbakk self-requested a review March 5, 2021 13:34
pyzeebe/task/task.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@kbakk kbakk left a comment

Choose a reason for hiding this comment

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

Approached this by going over the tests added/changed.

pyzeebe/task/task_config.py Outdated Show resolved Hide resolved
pyzeebe/worker/task_router.py Outdated Show resolved Hide resolved
tests/unit/worker/task_router_test.py Show resolved Hide resolved
tests/unit/worker/task_router_test.py Outdated Show resolved Hide resolved
tests/unit/worker/task_router_test.py Outdated Show resolved Hide resolved
def test_decorator_variables_are_added(self, original_task_function: Callable, decorator: TaskDecorator,
task_config: TaskConfig, mocked_job_with_adapter: Job):
decorator_return_value = mocked_job_with_adapter
decorator_return_value.variables = {"x": 2}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe create a helper function that returns {str(uuid4()): str(uuid4)}

pyzeebe/task/task_builder.py Outdated Show resolved Hide resolved
tests/unit/task/task_builder_test.py Outdated Show resolved Hide resolved
tests/unit/task/task_builder_test.py Show resolved Hide resolved
tests/unit/worker/worker_test.py Outdated Show resolved Hide resolved
@JonatanMartens JonatanMartens mentioned this pull request Mar 6, 2021
The dataclasses library is not supported in python 3.6
Copy link
Collaborator

@kbakk kbakk left a comment

Choose a reason for hiding this comment

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

Approached this review round from the code side (as well as verified the recent changes).

Looks good, some suggestions/changes needed. Impressive work, thanks for your commitment to this project!

pyzeebe/task/task_config.py Outdated Show resolved Hide resolved
pyzeebe/task/task_config.py Show resolved Hide resolved
pyzeebe/task/task_builder.py Show resolved Hide resolved
pyzeebe/task/task_builder.py Outdated Show resolved Hide resolved
pyzeebe/task/task_builder.py Outdated Show resolved Hide resolved
pyzeebe/task/task_builder.py Show resolved Hide resolved
pyzeebe/task/task.py Show resolved Hide resolved
pyzeebe/worker/task_router.py Outdated Show resolved Hide resolved
pyzeebe/worker/task_router.py Show resolved Hide resolved
@JonatanMartens
Copy link
Collaborator Author

Hey @kbakk, I implemented most of your suggestions, some replies to things I view differently/didn't understand. Could you take another look?

@JonatanMartens JonatanMartens changed the base branch from development to pre-release/3.0.0 March 15, 2021 20:26
@kbakk
Copy link
Collaborator

kbakk commented Mar 18, 2021

A couple of lint issues to address, otherwise good to merge I think:

  1. Refactor/task builder #131 (comment)
  2. Refactor/task builder #131 (comment)

@JonatanMartens
Copy link
Collaborator Author

Hey @kbakk, I decided that ZeebeTaskRouter.task should keep the same API as before. There is no benefit in forcing the user to create another object just to create a task. It also solves some of your comments and leads to some cleaner code. I would love it if you could take another look!

@JonatanMartens JonatanMartens requested a review from kbakk March 26, 2021 14:19
Copy link
Collaborator

@kbakk kbakk 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 here.

I think it's a good call to retain the task API.

Couple of comments, not important to address, so setting this to approved. Well done!

pyzeebe/worker/task_router.py Outdated Show resolved Hide resolved

def task_wrapper(fn: Callable):
task = task_builder.build_task(fn, config_with_decorators)
if single_value and not variable_name:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we move back this check to TaskConfig.__init__, and build the TaskConfig outside of the wrapper? It seems to belong there.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The task config is built here because we need the task_function to get variables_to_fetch

@JonatanMartens JonatanMartens merged commit 73feb0b into pre-release/3.0.0 Mar 27, 2021
@JonatanMartens JonatanMartens deleted the refactor/task-builder branch March 27, 2021 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants