-
Notifications
You must be signed in to change notification settings - Fork 61
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
Add option to skip herd avoidance check, but still trigger avoidance for other tasks #57
Comments
Let me know if this would be acceptable and I can work it into the implementation of #56 |
To make sure I understand, you're talking about adding the ability to "turn off" thundering herd avoidance at task "call time", rather than at task definition time, right? I'm a bit wary of adding any special kwargs that jobtastic hijacks, since it introduces the potential of existing jobtastic usages colliding with those special kwargs. Even if we use a long namespace like I think there's a way to achieve what you're looking for right now via subclassing: class FooTask(JobtasticTask):
significant_kwargs = [
('numerators', str),
('denominators', str),
]
herd_avoidance_timeout = 60
...
class FooSansHerdAvoidanceTask(FooTask):
herd_avoidance_timeout = 0 If that pattern doesn't actually work because of a Jobtastic implementation detail, then I'm super interested in making it work. It might also be a good use case to document. What do you think of the subclassing option to solve this? |
@winhamwr I didn't like that idea at first, but from the perspective of a reusable app I think you are definitely correct. That is the cleaner approach for extending celery tasks in a reusable app. |
@winhamwr So I've been trying to figure out why the subclass approach isn't giving the results I was looking for written as suggested. I think the boolean mentioned in the original code snippet is still required. It would just be a class attr instead of a method kwarg. Here is why: |
@winhamwr Do you have a suggestion for how to test this? I've submitted a PR that implements/documents the class attr |
err I didn't submit a PR I created a branch on my fork and pushed the changes |
@thenewguy I meant to take a look at this today. Sorry for the delay. I plan on taking a close look, tomorrow. |
@winhamwr Here is a direct link to the commit: thenewguy@410d735 I've been using it for awhile now and haven't noticed any issues |
@winhamwr not trying to pester you... but just checking back in on this |
@thenewguy thanks for your persistance! I appreciate it. I just re-reviewed #58 and it's ready to go with a very minor documentation tweak. As far as thenewguy/jobtastic@410d735, I think I now understand your use case based on rereading your March 16 comment. I'm trying to think of what name for the attr best-communicates that idea.
Since I can't think of anything that concisely explains the behavior, I lean towards something weird enough that motivates reading of the documentation. Thoughts? |
Also, for this feature, we definitely need an example in the README of how it could be used. So you're setting |
Still thinking about your attr naming comment but wanted to comment on the other... Correct. Forgive me if I am slightly rusty on the specifics of this now, but from memory and reading back through my code comments I encountered a race condition that made this distinction important. I can become more familiar if necessary but I don't think it will be at this point. Consider the use case of computing a hash based etag on a very large remotely stored file (aka hash generation is time consuming) that is used in the response url for long term caching. When the content that the hash is generated from changes, we know the etag needs to be recomputed. In this case we want to ensure the task is queued to prevent a stale etag. However, when generating redirect links based on the etag we do not actually want to compute a new etag. But, in this case, we do want to wait for the etag to update if it hasn't already to prevent redirecting to the stale content, so we latch onto the currently running job before returning |
|
That makes perfect sense. Thanks for the explanation and for sharing the code sample.
Overriding Re-reading the docs on that setting, I did a really bad job of explaining that. I'm glad you were able to get the desired behavior, anyway. |
This is my LockingTask mixin that covers some of your caveats:
|
I'm not sure how I lost track of this, but I've submitted a PR with the approved name |
@winhamwr any chance on merging? this one is killing me slowly <3 |
I have a situation where I would like to use thundering herd avoidance conditionally.
It would be easy to support this with a conditional check at https://github.com/PolicyStat/jobtastic/blob/master/jobtastic/task.py#L242 and pop the key out of the options that get passed to the superclass.
Something like the following should do the trick:
This would work nicely with #56
The text was updated successfully, but these errors were encountered: