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 the code to make task functions simple functions #15

Merged
merged 2 commits into from
Apr 14, 2019

Conversation

sdispater
Copy link

This PR makes the manager.task() method a true decorator by not altering the decorated function (except the addition of a defer() method to it to replicate the previous behavior).

What this allows is the ability to start decorating existing functions without modifying their signature (no task_run anymore) and leave them unit testable without relying on the internals of cabbage.

This code came up when trying to address #3 and I think if we go the route of this PR this makes the implementation of test specific tools in cabbage mostly unnecessary.

To sum it up, we can now have something like this:

from cabbage import TaskManager

manager = TaskManager()


@manager.task(queue="default")
def add(a, b):
    return a + b


add(1, 2)  # 3

cabbage/tasks.py Outdated Show resolved Hide resolved
@sdispater sdispater force-pushed the improve-testability branch from 839156d to 3a93c86 Compare April 12, 2019 08:20
Copy link
Member

@ewjoachim ewjoachim left a comment

Choose a reason for hiding this comment

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

This looks nice but, it means we can't access information on the current task anymore, right ? Like if we want to add the current task id in the log context or anything ?

(This may be solved later, I'm not against having an unstable API while we iterate)

@ewjoachim
Copy link
Member

ewjoachim commented Apr 12, 2019

@mgu @k4nar @Evelf I'd like a second opinion

@ewjoachim ewjoachim requested review from mgu, k4nar and Evelf April 12, 2019 22:55
Copy link

@mgu mgu left a comment

Choose a reason for hiding this comment

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

I share you concerns @ewjoachim (about accessing current task information).
Nevertheless I like what has been made here 👍

@ewjoachim
Copy link
Member

Ok, let's merge it then, and we'll see later how we want to access current task info.

Maybe we will add a parameter to the task decorator to decide if we want to pass this or not... In a later PR :D

@ewjoachim
Copy link
Member

Hoping it's ok with everyone, I'll merge now, because I'd like to have a go at some tickets today.

@ewjoachim ewjoachim merged commit 61f1684 into master Apr 14, 2019
Copy link
Contributor

@k4nar k4nar left a comment

Choose a reason for hiding this comment

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

LGTM

@ewjoachim ewjoachim deleted the improve-testability branch August 3, 2019 22:30
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.

4 participants