Commit Graph

3386 Commits

Author SHA1 Message Date
Fabio Manganiello a8255f3621
Pass the configuration file used by the application to the Alembic process.
The database settings could also be overridden in the configuration file
besides the command line.

We should therefore pass the path to the runtime configuration file, so
the Alembic process can initialize its configuration from the same file
and use the same settings.
2023-08-19 13:23:20 +02:00
Fabio Manganiello 1825b492b3
Replaced `Config.workdir` with `Config.get_workdir()`.
Again, Python < 3.9 doesn't like class properties.
2023-08-19 13:21:24 +02:00
Fabio Manganiello a8836f95f5
Support explicit `workdir` parameter override in `Config` constructor. 2023-08-19 13:15:29 +02:00
Fabio Manganiello 5bc82dfe64
s/Config._cfgfile/Config.config_file/g 2023-08-19 13:13:36 +02:00
Fabio Manganiello 181da63c89
Pass the database engine to the Alembic process as an extra argument.
If the path of the default database engine is overridden via `--workdir`
option then it won't be visible to the new `python` subprocess spawned
for Alembic.
2023-08-19 13:02:05 +02:00
Fabio Manganiello c2b3ec8ce3
Fixed manifest files with outdated formats. 2023-08-19 12:54:33 +02:00
Fabio Manganiello e463a52435
Use `sys.executable` rather than `'python'` to launch the application. 2023-08-19 12:40:57 +02:00
Fabio Manganiello 0a5fc40dc5
Merge branch 'master' into 276/better-docker 2023-08-18 17:34:56 +02:00
Fabio Manganiello 3236e235ef Merge pull request '278/fix-variable-errors-on-python-3-8' (#279) from 278/fix-variable-errors-on-python-3-8 into master
continuous-integration/drone/push Build is failing Details
continuous-integration/drone Build is running Details
Reviewed-on: #279
2023-08-18 17:25:08 +02:00
Fabio Manganiello 2cab836bdf
`Entity.columns` class property replaced by `Entity.get_columns` method.
continuous-integration/drone/push Build is passing Details
Again, Python < 3.9 doesn't like the combination of `@property` +
`@classmethod`.
2023-08-18 17:20:53 +02:00
Fabio Manganiello a9cdff900e
_variable should be an external global function rather than a class property.
The combination of `@property` + `@classmethod` isn't supported on
Python < 3.9.
2023-08-18 16:16:47 +02:00
Fabio Manganiello d0c89f88a8
Fixed parenthesised multi-with statement.
This syntax is not supported on Python < 3.9, and therefore it should be
broken down as a multi-line statement.
2023-08-18 16:10:31 +02:00
Fabio Manganiello ca95490412
Added timeout parameter to requests.get in the rss plugin.
continuous-integration/drone/push Build is passing Details
2023-08-18 15:53:30 +02:00
Fabio Manganiello 5dd7345c0b
Sync the latest parse timestamps in main instead of __init__ in rss.
We should load the latest timestamps from the db when the thread starts
instead of doing it in the constructor.

The constructor may be invoked when the entities engine hasn't been
initialized yet, and result in deadlocks.
2023-08-18 15:51:11 +02:00
Fabio Manganiello ec64b0ef8b
Added `--device_id` command line option.
continuous-integration/drone/push Build is failing Details
2023-08-17 23:16:24 +02:00
Fabio Manganiello ac83b43f98
Support for custom key-value overrides on `Config.init`. 2023-08-17 22:03:39 +02:00
Fabio Manganiello 657b2cc87d
Create the default configuration file even if --config is supplied but the file doesn't exist.
continuous-integration/drone/push Build is failing Details
2023-08-17 11:25:49 +02:00
Fabio Manganiello afa4de5673
Dockerfile moved to application root
continuous-integration/drone/push Build is passing Details
2023-08-17 10:38:21 +02:00
Fabio Manganiello 24b04d9103
s/--config-file/--config/ option in Dockerfile.
continuous-integration/drone/push Build is failing Details
2023-08-17 10:35:40 +02:00
Fabio Manganiello f07b774e75
A better Dockerfile.
continuous-integration/drone/push Build is passing Details
2023-08-17 03:04:34 +02:00
Fabio Manganiello bf7d060b81
Added `@ensure_initialized` decorator to actions in `variable`.
continuous-integration/drone/push Build is passing Details
The `variable` plugin may break in the constructor the first time the
application is started.

That's because it tries to initialize the cache of stored variables, but
the local database hasn't yet been initialized.

That's because plugins are registered _before_ the entities engine is
initialized, as the entities engine assumes that it already has plugins
to scan for entities.

Therefore, the initialization of the `variable` plugin's cache should be
lazy (only done upon the first call to `get`/`set` etc.), in order to
prevent deadlock situations where the plugin waits for the engine to
start, but the engine will be initialized only after the plugin is
ready.

And the lazy initialization logic should also ensure that the entities
engine has been properly started (and emit a `TimeoutError` if that's
not the case), in order to prevent race conditions.
2023-08-17 02:47:30 +02:00
Fabio Manganiello adfedfa2dd
s/TimeoutError/AssertionError/ if get_entities_engine times out. 2023-08-17 02:36:40 +02:00
Fabio Manganiello ec2b8da983
Ignore Redis errors when a backend sends an unregister notify event.
When that happens, it's most likely that the application is already
stopping and the Redis service has already been terminated.
2023-08-17 01:49:41 +02:00
Fabio Manganiello 3bf068e0b2
The __main__ function should take no arguments.
setup.py won't pass any arguments to `main()`, so the default entry
point should get them itself from `sys.argv`.
2023-08-17 01:35:39 +02:00
Fabio Manganiello a52de0e086
Removed tz dependency. 2023-08-17 00:35:39 +02:00
Fabio Manganiello e9dbcff1a8
Removed old `bin/platypush` script.
It's already been replaced by the setup.py entry point.
2023-08-16 23:52:54 +02:00
Fabio Manganiello 98e9abde18
Extended manifest files with Python system packages (if available).
continuous-integration/drone/push Build is passing Details
- If a Python optional dependency is available as a system package on
  the target system, try and install it that route rather than pip. It's
  usually faster and it decreases the risk of breaking system packages.

- Added support for apk dependencies in manifest files. This brings the
  number of distros officially supported by all the extensions to four:

  - Alpine
  - Arch
  - Debian
  - Ubuntu
2023-08-16 22:43:51 +02:00
Fabio Manganiello c2a17f0d75 Merge pull request '[#272] Support for external stop/restart control on the application' (#273) from 272/external-proc-controller into master
continuous-integration/drone/push Build is passing Details
Reviewed-on: #273
2023-08-15 21:34:43 +02:00
Fabio Manganiello fef6513cc8
Alpine Linux requires the linux-headers package to build psutil.
continuous-integration/drone/push Build is passing Details
2023-08-15 11:40:02 +02:00
Fabio Manganiello 00863a176e
Added `application` plugin.
continuous-integration/drone/push Build is failing Details
2023-08-15 11:20:24 +02:00
Fabio Manganiello f51beb271e
Large refactor + stability fixes for the external process control logic. 2023-08-15 11:12:21 +02:00
Fabio Manganiello 46245e851f
Synchronize with the currently running stop thread (if any) in `Backend.wait_stop`. 2023-08-15 02:08:47 +02:00
Fabio Manganiello a8a7ceb2ac
Implemented `HttpBackend._stop_workers`.
The Tornado WSGI container won't guarantee the termination of the
spawned workers upon termination, so the code of the backend has to take
care of it and terminate all the children processes of the server
process when it terminates.

This also means that `psutil` is now a required base dependency, as we
need to expand the process subtree under the webserver launcher.
2023-08-15 00:13:34 +02:00
Fabio Manganiello 04921c759f
Added `wait_stop` method to the entities engine and cron scheduler. 2023-08-14 23:49:47 +02:00
Fabio Manganiello ceb9d6d1ba
Removed redundant `Backend._get_redis()` method.
It was used only once, and it could easily be replaced by
`platypush.utils.get_redis()`.
2023-08-14 23:37:38 +02:00
Fabio Manganiello 7157936b87
Added get_remaining_timeout utility function. 2023-08-14 23:17:50 +02:00
Fabio Manganiello dc1a152433
Added `get_default_pid_file` utility method. 2023-08-14 10:47:25 +02:00
Fabio Manganiello c11bc69a66
Handle `KeyboardInterrupt` and process return code in the main. 2023-08-13 23:55:40 +02:00
Fabio Manganiello 8819a0ed4c
Added `CommandStream` to the main `Application`.
The stream will be used to communicate command messages from the
application to its runner.
2023-08-13 23:51:21 +02:00
Fabio Manganiello 06111587f7
Added `CommandStream` class.
This abstraction is used to write and read commands over a UNIX socket.
2023-08-13 23:37:51 +02:00
Fabio Manganiello c89f992867
Added `StopCommand` and `RestartCommand`. 2023-08-13 23:36:36 +02:00
Fabio Manganiello b1f244a812
Added `ControllableProcess` class.
This class can be used to easily control the execution of underlying
processes.
2023-08-13 23:33:08 +02:00
Fabio Manganiello efef9d7bc0
Added `commands` module. 2023-08-13 23:21:36 +02:00
Fabio Manganiello 97adc3f775
Moved application argument parser to an external `platypush.cli` module. 2023-08-13 22:27:16 +02:00
Fabio Manganiello 1819ee75ef
`s/Application.stop_app/Application.stop/g` 2023-08-13 22:23:15 +02:00
Fabio Manganiello 827b564006
Using a single constant for DEFAULT_REDIS_QUEUE.
Also, catch `AttributeError` on `self._proc.terminate` in the
`HttpBackend`, since the process may already have been terminated and
set to null by another worker process.
2023-08-13 22:20:16 +02:00
Fabio Manganiello 4062ddbcf0
More improvements to the `inspect` plugin.
continuous-integration/drone/push Build is passing Details
- Support for distinct `type` field on constructor and method arguments.

- Added `has_varargs` field.

- Added `required` field.

- Better logic for parsing arguments `default` values.
2023-08-08 20:47:27 +02:00
Fabio Manganiello 9beb0a7af3
Skip `:type:` annotations from docstring args documentation. 2023-08-08 20:47:27 +02:00
Fabio Manganiello 2a30f060b4
Parse the arguments list from `obj_type.__init__.__doc__` too. 2023-08-08 20:47:27 +02:00
Fabio Manganiello 1474685cc0
[Automatic] Updated UI files
continuous-integration/drone/push Build is passing Details
2023-08-06 22:51:57 +00:00