feat(manual-mode): Add manual model#84
Conversation
4b7f6dc to
47bd33b
Compare
|
|
||
| ctx = ExitStack() | ||
| timer = metrics.flagsmith_task_processor_task_duration_seconds.time() | ||
| ctx.enter_context(timer) |
There was a problem hiding this comment.
I had to do this because this is evaluated at import time as a result flagsmith_task_processor_task_duration_seconds is not part of the metrics
There was a problem hiding this comment.
I believe reload_metrics should solve this? See usage
There was a problem hiding this comment.
That still feels like a hack to me. I want this to be a first-class feature so that anyone updating or changing the task processor code is aware of this use case as well
|
There are currently two modes that affect the runtime behaviour of the task processor: While I understand the rationale behind adding a new My suggestion:
|
That's not entirely true, though? We do have |
|
@gagantrivedi The |
|
@khvn26 I get your point. I'd argue that a manual mode intuitively makes sense for the task processor compared to all the fixture/patching stuff. IMO, Digging into this general idea of adding features just to make developers' lives easier (even if unrelated to the main goal), I found that quite a few libraries do that. |
This is why I'm inclined to expose a fixture with a clear purpose and a use case rather than another, arguably vague, Django setting. |
|
I understand the value added in this patch, though I'm inclined to agree with @khvn26 on the design side, as I also don't favor implementing runtime code only to support tests. I don't like hacking through import time either, if I can possible look elsewhere for a better design decision that might favor both the app and tests. Though I'm unsure if this is the only pain point solved by this PR, I suggest adding a new setting Note that changing this new setting within a test might not immediately enable URLs because the urlconf module has already been loaded. If that proves true, I believe pytest-django's urls marker might somehow help. |
Great idea 👍 This could be extended to
I haven't personally checked this, but according to @gagantrivedi's experience, the URL configs are reloaded whenever the
Nice find, and potentially the cleanest solution yet 👍 Having different urlconf modules for API and Task processor sounds nicer for runtime purposes as well. |
|
Just to rephrase the problem from where I stand: The issue is that setting
I'm somewhere in between. I agree that being able to run tasks manually in tests is a great tool to speed up development and confidence, but I also lean towards @khvn26 concern about introducing test-specific behavior into runtime code. |
|
I'd say that my standpoint is that I definitely align most with this sentiment:
That being said, in general, the solution in this PR is pretty light on the runtime interference. I think it's hard to make a decision here without seeing a PoC for @khvn26's suggestion as I'm having a hard time envisaging it without anything tangible. |
Add
TASK_PROCESSOR_MANUAL_MODE, which can be used in tests that depend on the task processor by manually callingrun_tasks.Usage example: https://github.com/Flagsmith/flagsmith-private/pull/29/files#diff-d390474f304862c0fc4fd05287524aa5702182dccec6db49ff58fab474996630R240