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

Store tiger instance in global task context #170

Merged
merged 6 commits into from Dec 17, 2020

Conversation

thomasst
Copy link
Member

This makes it easier for libraries (e.g. FlowFish) to access the TaskTiger instance to queue further tasks.

from tasktiger._internal import g

def my_task(...):
    tiger = g["tiger"]
    tiger.delay(more_tasks)

I don't like that it's importing _internal but wasn't sure if there's a good way to expose it, perhaps just from tasktiger import g?

@thomasst thomasst self-assigned this Dec 16, 2020
Copy link
Member

@jkemp101 jkemp101 left a comment

Choose a reason for hiding this comment

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

I think we should keep g hidden so we can refactor without breaking things. Expose it with a helper function or class method on TaskTiger? And do we need to ensure the Redis connections are closed before the child process uses it since we would be reusing the attached Redis instance from the parent process? I thought we did that somewhere but could find it with a quick search.

@thomasst
Copy link
Member Author

The Redis connection is closed before forking in _execute, so we should be good. I added a class property, TaskTiger.current_instance.

Copy link
Member

@jkemp101 jkemp101 left a comment

Choose a reason for hiding this comment

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

Add a test or two and do we need to set it here also for eager tasks?

tasktiger/tasktiger/task.py

Lines 292 to 297 in f6ed7b5

def execute(self):
func = self.func
is_batch_func = getattr(func, '_task_batch', False)
g['current_task_is_batch'] = is_batch_func
g['current_tasks'] = [self]

@thomasst
Copy link
Member Author

Good catch with eager tasks.

@thomasst thomasst merged commit 6064c95 into master Dec 17, 2020
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

2 participants