Make Executor.get_function_and_kwargs the overridable resolution hook. - #46
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 24_4 #46 +/- ##
==========================================
+ Coverage 71.26% 71.31% +0.05%
==========================================
Files 55 55
Lines 2899 2894 -5
==========================================
- Hits 2066 2064 -2
+ Misses 833 830 -3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
This one was originally intentional, as significant care has to be taken when crossing process/thread/sub-interpreter barriers. But your use case is definitely valid and this is definitely safe in the async executor. I'll give the others a closer review. |
|
Hey @TkTech, would you have the time to have another look at this PR ? May it be part of 0.24.4 ? |
|
#49 will release tomorrow with this supported at least for the async executor. Could you expand on your use case for this one? Is the kwarg you want to inject related to Chancy itself, like job or queue data, or your own? |
|
…TkTech#46) Custom executors need a supported way to inject their own keyword arguments (database pools, clients, ...) into every job they run. The built-in executors resolved the function through a private static helper that ignored subclass overrides, so the public get_function_and_kwargs was never consulted. get_function_and_kwargs is now a classmethod holding the resolution logic, and prepare_job_for_execution goes through it for every executor. The job-context detection used by co-operative time limits now checks the resolved kwargs for the job instance instead of a side channel, so overrides cannot break it. Co-authored-by: PaulM5406 <ppsmilesi@protonmail.com>
acb2407 to
4e15556
Compare
…TkTech#46) Custom executors need a supported way to inject their own keyword arguments (database pools, clients, ...) into every job they run. The built-in executors resolved the function through a private static helper that ignored subclass overrides, so the public get_function_and_kwargs was never consulted. get_function_and_kwargs is now a classmethod holding the resolution logic, and prepare_job_for_execution goes through it for every executor. The job-context detection used by co-operative time limits now checks the resolved kwargs for the job instance instead of a side channel, so overrides cannot break it. Because job_wrapper and prepare_job_for_execution are classmethods, the override runs on the side that executes the job (event loop, pool thread, sub-interpreter or child process); nothing crosses that boundary beyond the executor's importable name. The docstring spells this out and an end-to-end test checks the injection on every built-in executor. Co-authored-by: PaulM5406 <ppsmilesi@protonmail.com>
4e15556 to
35d5cb2
Compare
|
Taking over this PR from @PaulM5406, context in #58 (comment). It is now retargeted to Use case, as Paul described: a custom executor injecting application-level dependencies (connection pools, API clients) as keyword arguments into every job, without wrapping each job function. On What changes
|
On The updated PR only routes the resolution through the public name instead of the private helper. The docstring now spells out where the method runs and what that implies, and |
|
Merged in #58, with one change to the docstring (async and threaded executors can generally share objects) |
Hey @TkTech,
I would like to be able to override
get_function_and_kwargsin custom executor to be able to dynamically inject other kwargs like it is possible withQueueJob.Thanks !