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

[IMPL] - Custom backend server and improved configuration capabilities #4337

Open
wants to merge 49 commits into
base: main
Choose a base branch
from

Conversation

KronosDev-Pro
Copy link

@KronosDev-Pro KronosDev-Pro commented Nov 8, 2024

Idea

Customize the backend server configuration as you like, and create a complete new backend server support.

can be easily split into another reflex package, for example pip install reflex[granian].

Example

We can define which BackendServer to use for development and production modes and thus customize the configuration (all parameters for each BackendServer are the actual parameters corresponding to the web server involved).

import reflex as rx
from reflex import server

config = rx.Config(
    app_name="examples",
    backend_server_dev = server.GunicornBackendServer(
        worker_class="uvicorn.workers.UvicornH11Worker",
        max_requests=100,
        max_requests_jitter=25,
        timeout=120,
        threads=1,
        workers=1,
    ),
    backend_server_prod = server.GranianBackendServer(
        threads=2,
        workers=4,
    )
)

We can also create a customized BackendServer with the CustomBackendServer class, such as GranianBackendServer


All Submissions:

  • Have you followed the guidelines stated in CONTRIBUTING.md file?
  • Have you checked to ensure there aren't any other open Pull Requests for the desired changed?

Type of change

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

New Feature Submission:

  • Does your submission pass the tests?
  • Have you linted your code locally prior to submission?

Changes To Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

@mmmcorpsvit
Copy link

hm... why not just use Pydantic Config package?

@KronosDev-Pro
Copy link
Author

hm... why not just use Pydantic Config package?

Basically, dataclasses is a native package that brings simplicity, performance and more customization possibilities. What's more, for this type of configuration, it doesn't need the validation and serialization/deserialization provided by pydantic.

KronosDev-Pro and others added 23 commits November 13, 2024 15:34
* require typing_extensions >= 4.6.0

TypeAliasType was added in 4.6

https://github.com/python/typing_extensions/blob/main/CHANGELOG.md#release-460-may-22-2023

* update lock file, even though nothing has changed
* make list suggestions work

* fix pyi
* bump some versions

* update ruff to 0.7.4

* bump tailwind version

* relock deps

---------

Co-authored-by: Masen Furer <[email protected]>
* fix: do not allow instantiation of State mixins
Closes reflex-dev#4343

* improve error message for ComponentState mixins

* fix typo

Co-authored-by: Masen Furer <[email protected]>

---------

Co-authored-by: Masen Furer <[email protected]>
* add typed dict type checking

* technically it has to be a mapping, not specifically a dict
* Add datetime to moment

* Remove recharts update

* Support other formats

* simplify

* Precommit

* PYI

* change imports for pyi compat

---------

Co-authored-by: Alek Petuskey <[email protected]>
Co-authored-by: Masen Furer <[email protected]>
* ignore rxconfig not in cwd

* no type ignore

* resolve paths

* Remove rxconfig module from sys.modules cache when reloading

* modify sys path

* add try except

* refactor inner function

---------

Co-authored-by: Masen Furer <[email protected]>
* fix appearance broken by reflex-dev#3812

* fix again to pass tests
)

The `rich` module should be set to `None`, indicating that rich should not be used.

Setting it to `False` worked before, but recently added code in typer fails
when checking `if rich is not None`.

ref: fastapi/typer#847
…v#4410)

In some cases, a routing failure can cause the failure to be cached. When the
router has a cached failure, pushing such a route will never call
routeChangeComplete, and thus on_load event will never be fired for that route.

Purposely clearing the error from the router allows the page to properly load
on subsequent attempts without refreshing the app.
Compiling pages in separate threads can result in `sys.path` being cleared,
which breaks subsequent imports.
* subtract 1 arg if the method is a bound method

* fix it early in user_args

* only bound methods pls

* add test
masenf and others added 12 commits November 21, 2024 16:15
* Handle Var passed to `rx.toast`

If the user provides a `Var` for `message` then apply it as `props["title"]` to
avoid a var operations error.

* remove unnecessary parentheses

* remove weird hacks

* get it right pyright

---------

Co-authored-by: Khaleel Al-Adhami <[email protected]>
When an event/event spec is marked as "temporal", it will not be queued unless
the backend is up. This can be used to prevent periodic events (like from
`rx.moment`) from queueing up while the backend is down, and then stampeding
when the backend comes up and the queue is drained. It can be used to avoid
processing many periodic events at once when the app is only expecting to
process such an event every so often.
* Rework Init workflow

* minor format

* refactor

* add comments

* fix pyright alongside some improvements

* add demolink for blank template

* fix darglint

* Add more templates and keep template name in kebab case

* revert getting other templates since we'll use the submodules approach

* remove debug statement

* Improvements based on standup comments

* Add redirect logic

* changes based on new flow

---------

Co-authored-by: Masen Furer <[email protected]>
…x-dev#4338)

* [ENG-3953] Support pydantic BaseModel (v1 and v2) as state var

Provide serializers and mutable proxy tracking for pydantic models directly.

* conditionally define v2 serializer

Co-authored-by: Khaleel Al-Adhami <[email protected]>

* Add `MutableProxy._is_mutable_value` to avoid duplicate logic

* Conditionally import BaseModel to handle older pydantic v1 versions

* pre-commit fu

---------

Co-authored-by: Khaleel Al-Adhami <[email protected]>
* wip rx._x.asset improvements

* only add symlink if it doesn't already exist

* minor improvements, add more tests

* use deprecated Generator for python3.8 support

* improve docstring

* only allow explicit shared, only validate local assets if not backend_only

* fix darglint

* allow setting backend only env to false.

* use new is_backend_only in assets

* ruffing

* Move to `rx.asset`, retain old API in `rx._x.asset`

---------

Co-authored-by: Masen Furer <[email protected]>
* update cli version

* little change man

* thats ruff

* v bump

---------

Co-authored-by: simon <[email protected]>
@KronosDev-Pro KronosDev-Pro marked this pull request as ready for review November 23, 2024 21:17
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.

9 participants