Commit Graph

114 Commits

Author SHA1 Message Date
Fabio Manganiello 666ea9ea6b
Added `use_werkzeug_server` option to `backend.http`.
There are situations where you may not want to run the HTTP server in a
full blown WSGI-over-Tornado container - unit/integration tests and
embedded single-core devices are among those cases.

In those scenarios, we should allow the user to be able to run the
backend using the built-in Werkzeug server provided by Flask.
2023-05-20 15:26:58 +02:00
Fabio Manganiello 72797e73ff
Changed the Tornado paradigm to start the WSGI workers.
Use `bind_sockets`/`fork_processes` instead of reinventing the wheel
with our own multiprocessing handling.
2023-05-13 12:35:20 +02:00
Fabio Manganiello ac4fe4447e
Revert "Added a multi-worker approach to the Tornado WSGI container."
This reverts commit 71401a4936.

Temporarily reverted this commit because the `reuse_address` on the
application's `listen` method has only been implemented in Tornado 6.2 -
and Debian stable still shipts Tornado 6.1.
2023-05-13 02:36:20 +02:00
Fabio Manganiello 71401a4936
Added a multi-worker approach to the Tornado WSGI container.
The WSGI container is a good option to wrap a multi-modal webapp
(Flask + websocket routes), but it's constrained to a single-process
approach and queued/pre-buffered requests. That makes performance poor
when handling requests that may take a few seconds to complete.
2023-05-13 01:26:18 +02:00
Fabio Manganiello a069d23bb7
[#260] Added ``/ws/requests`` websocket route. 2023-05-09 02:40:32 +02:00
Fabio Manganiello edb7197f71
[#260] Implemented authentication for websocket routes.
Plus, refactored the `backend.http.app.utils` module by breaking it down
into multiple components, as the module was starting to get too large.
2023-05-09 00:03:11 +02:00
Fabio Manganiello f5fcccb0bd
Refactored the new websocket routes.
Defined a `platypush.backend.http.ws` package with all the routes, a
base `WSRoute` class that all the websocket routes can extend, and a
logic in the HTTP backend to automatically scan the package to register
exposed websocket routes.
2023-05-08 11:45:14 +02:00
Fabio Manganiello 56dc8d0972
Migrated the webapp to Tornado.
It was just too painful to find a combination of versions of  gunicorn,
gevent, eventlet, pyuwsgi etc. that could work on all of my systems.

On the other hand, Tornado works out of the box with no headaches.

Also in this commit:

- Updated a bunch of outdated/required integration dependencies.
- Black'd and LINTed a couple of old plugins.
2023-05-08 02:06:45 +02:00
Fabio Manganiello f81e9061a3
`lifespan=on` is actually not required on Flask config level. 2023-05-07 16:30:41 +02:00
Fabio Manganiello 692180c653
Back to uvicorn workers from eventlet.
The eventlet API has way too many dependency issues with gunicorn.

Still TODO: Fix or at least mitigate the WSGI workers timeout issue when
they handle websocket connections.
2023-05-07 15:37:58 +02:00
Fabio Manganiello f9b0bc905e
Migrated websocket service.
The websocket service is no longer provided by a different service,
controlled by a different thread running on another port.

Instead, it's now exposed directly over Flask routes, using
WSGI+eventlet+simple_websocket.

Also, the SSL context options have been removed from `backend.http`, for
sake of simplicity. If you want to enable SSL, you can serve Platypush
through a reverse proxy like nginx.
2023-05-07 12:08:28 +02:00
Fabio Manganiello 3aefc9607d
Migrated from waitress to gunicorn.
`waitress`, unlike `gunicorn`, doesn't provide an easy way to plug into
a WSGI socket that can be used for the websocket interface.
2023-05-07 00:42:57 +02:00
Fabio Manganiello 9951d62511
Added logic to automatically generate the secret key for Flask. 2023-05-06 22:04:48 +02:00
Fabio Manganiello 285f3941d9
Always use an external uWSGI server to run the web service.
Added `waitress` dependency. For performance and security reasons, it's
better to always run the Flask application inside of a uWSGI server.

`waitress` also makes things easier by avoiding to ask the user to
manually provide the external executable arguments, as it was the case
with `uwsgi` and `gunicorn`.
2023-05-05 00:07:13 +02:00
Fabio Manganiello cc2ec1db7f
The HTTP Zeroconf service should be registered before the server starts. 2023-05-02 21:24:50 +02:00
Fabio Manganiello e49a0aec4d
Various improvements.
- Better synchronization logic on stop for `AsyncRunnablePlugin`.
- Fixed several thread names by dropping `prctl.set_name` in favour of
  specifying the name directly on thread creation.
- Several LINT fixes.
2023-02-08 00:46:50 +01:00
Fabio Manganiello edddc90d73
Run register_service in a separate thread in `backend.http`.
The Zeroconf registration part may randomly get stuck, resulting in the
web server not being properly started.

It's therefore better to run the Zeroconf registration process
asynchronously, for it's not strictly required for the web server to
execute.
2023-01-01 13:16:46 +01:00
Fabio Manganiello fee5fc4ae0
HTTP backend dependencies moved from optional to required
If Platypush is supposed to work also without a manually created
`config.yaml`, and the HTTP backend is enabled by default in that
configuration, then Flask and companions should be among the required
dependencies.
2022-04-27 14:52:41 +02:00
Fabio Manganiello fa708663e1
Replaced command-line uwsgi wrapper in the backend.http docs with gunicorn
gunicorn makes it easier to set up a uWSGI wrapper
around the web application, and it's easier to
install and document than handling uwsgi as an
external system dependency.
2021-12-11 22:44:00 +01:00
Fabio Manganiello 49676fcc7f
Don't fail hard if the Zeroconf service can't be registered 2021-10-24 02:54:20 +02:00
Fabio Manganiello 1a314ffd6b Fixed LGTM errors and warnings 2021-09-17 22:21:29 +02:00
Fabio Manganiello 3bfc5b83ef Moved to manifest files for describing plugins and backends and their dependencies 2021-09-16 17:53:40 +02:00
Fabio Manganiello 090e7d6de8 Support for specifying the application Redis queue from the command line or service constructor 2021-03-06 19:22:13 +01:00
Fabio Manganiello b4f9472fc5 - Proper expansion of the context variables on functional procedure call
- Expanded and refactored tests framework

- Added test_procedure
2021-02-27 15:01:25 +01:00
Fabio Manganiello 2800bac3fb Make sure that all hanging threads, backends and services are stopped and their resources cleaned up when the application stops. 2021-02-23 23:09:26 +01:00
Fabio Manganiello 04a23d555d Updated README (it hadn't been updated for ages) 2021-02-22 02:53:20 +01:00
Fabio Manganiello 6df336465f Fixed nested list style in backend.http documentation 2021-02-22 01:35:42 +01:00
Fabio Manganiello ffb7a3e5a3 Extended and updated pieces of documentation on the HTTP server, Zigbee2mqtt and mpd. Also added example dashboard template and event hook script. 2021-02-22 01:20:01 +01:00
Fabio Manganiello 04cb2324aa Removed dashboard configuration from HttpBackend, removed old HTTP
static files and replaced them with Vue app target dist/ directory.
2020-11-26 11:54:28 +01:00
Fabio Manganiello 7e8bef40cd Added Zeroconf integration [closes #105] 2020-08-14 00:36:39 +02:00
Fabio Manganiello c5adc141ea More robust mechanism for websocket message send section locking 2020-02-06 19:30:40 +01:00
Fabio Manganiello ca030c9b25 Websocket notifications delivery should be thread-safe.
If multiple threads process events and notify the websocket
clients at the same time then we may end up with inconsistent
messages delivered on the websocket (and websockets is not
designed to handle such cases). Protecting the send call with
a per-socket lock makes sure that we only write one message
at the time for a certain client.
2020-02-06 01:04:36 +01:00
Fabio Manganiello 8bfe875483 We don't need to fail hard in backend.http if the backend is configured
to run the web server externally but without spawning uswgi directly
(e.g. if nginx takes care of spawning and wrapping the uwsgi instance)
2019-08-14 20:02:13 +02:00
Fabio Manganiello 4cd2e6949f New media webplugin WIP 2019-06-21 02:13:14 +02:00
Fabio Manganiello 8b478ede45 vue.js migration commit - WIP 2019-05-28 19:16:55 +02:00
Fabio Manganiello 68f985d2c6 Copy websockets list before iterating over it to prevent race conditions upon list changed upon iteration 2019-03-27 02:25:06 +01:00
Fabio Manganiello 811af1bf9d Removed conflict leftovers 2019-02-26 23:55:00 +01:00
Fabio Manganiello 17367f5b3e Added camera plugin over cv2 2019-02-26 23:50:48 +01:00
Fabio Manganiello 150d95d0dc Support for launching uWSGI directly from the HTTP backend 2019-02-25 10:52:48 +01:00
Fabio Manganiello 8ef3aafb52 Added missing doc line in backend.http 2019-02-24 15:53:01 +01:00
Fabio Manganiello 8153d8476f Added uWSGI optional dependency for HTTP backend 2019-02-24 12:35:26 +01:00
Fabio Manganiello c74b939660 Renamed app->application for the main Flask webapp to make sure that the default uwsgi configuration can pick it up 2019-02-24 00:11:35 +01:00
Fabio Manganiello 0e794cd1b0 Refactored HTTP server to split the routes on separate files and keep the main Flask app object in a separate file as well so it can be easily wrapped by a WSGI instance 2019-02-23 21:19:00 +01:00
Fabio Manganiello 6e1b6686c2 Revert "Running Flask webserver in another thread instead than another process"
This reverts commit 0a5c42fdfd.
2019-02-21 16:15:06 +01:00
Fabio Manganiello 0a5c42fdfd Running Flask webserver in another thread instead than another process 2019-02-21 14:33:41 +01:00
Fabio Manganiello 5cbd0fdfe7 Added support for VTT subtitles and subtitles toggling both in local and browser media players 2019-02-12 01:30:55 +01:00
Fabio Manganiello 41c34b4bc5 Attempt to support subtitle tracks in web player 2019-02-11 18:46:25 +01:00
Fabio Manganiello 34f0264d5e Subtitles support
- Added support for local and OpenSubtitles media subs
- Added management of media events in web panel
2019-02-11 00:55:20 +01:00
Fabio Manganiello e2b0bf8462 More consistent management of media devices icons and added devices refresh button 2019-02-08 19:48:18 +01:00
Fabio Manganiello b3f2974c4c Support for streaming media to browser 2019-02-08 00:43:43 +01:00