Commit Graph

77 Commits

Author SHA1 Message Date
Fabio Manganiello f8e0b5e17e
[#366] Context variables should be dynamically assigned through `locals()` instead of `exec()`.
continuous-integration/drone/push Build is passing Details
Closes: #366
2024-02-26 21:29:35 +01:00
Fabio Manganiello 9c3da7a2a9
Several improvements for request/procedure execution.
continuous-integration/drone/push Build is passing Details
- Fixed regression introduced by incorrect format string in `exec`.

- LINT for the `procedure` module.

- Apply `Message.Encoder` when dumping values from the context.
2024-01-04 13:13:16 +01:00
Fabio Manganiello 0dc380fa94
Removed dependency from prctl.
Also, black'd and LINT-fixed some files that hadn't been touched in a
while.
2023-07-23 19:17:30 +02:00
Fabio Manganiello cef9d0e007
Always serialize exception names when logging/returning request exceptions. 2023-07-22 15:13:17 +02:00
Fabio Manganiello fa1364d854
Improved logging for requests, responses and events.
- The following logging namespaces are now used, to make it easier to
  filter only log lines related to the logged application message:

  - `platypush:events`
  - `platypush:requests`
  - `platypush:responses`

- Those messages are always logged as JSON, with no prefixes nor
  suffixes.

- Requests are always logged when executed - no more delegation to the
  upstream backend.

- Responses are always logged when fully populated (including `id`,
  `origin`, `target` etc.), instead of being logged when still partially
  populated. This makes it particularly easy to link request/response
  IDs directly from the logs.
2023-07-15 01:11:45 +02:00
Fabio Manganiello d4b540dd67
Replaced `disable_logging` with a more generic `logging_level`.
The `disable_logging` attribute was only available on events and
responses, and it could only either entirely disable or enable logging
for all the events of a certain type.

The new flag allows more customization by setting the default logging
level used for any message of a certain type (or `None` to disable
logging). This makes it possible to e.g. set some verbose events to
debug level, and the user can see them if they configure the application
in debug mode.

It also delegates the logging logic to the message itself, instead of
having different parts of the application handling their own logic.
2022-12-11 11:39:38 +01:00
Fabio Manganiello 550f026e13
Cleaner logging for assertion errors in plugin actions 2022-08-25 00:30:53 +02:00
Fabio Manganiello 55671f4aff
If a request on a RunnablePlugin throws an exception then we should also restart the plugin upon reload
Plus some Black/LINT chores
2022-07-25 00:41:08 +02:00
Fabio Manganiello e3f0219554 Errors should be caught also before a request action is executed (prevents HTTP timeouts when the error is on e.g. get_plugin() level) 2021-10-01 23:40:43 +02:00
Fabio Manganiello 2a78f81a7b Major LINT fixes 2021-04-05 00:58:44 +02:00
Fabio Manganiello 8db8f3e6c4 Unparseable context variables should be logged on debug, not warning, level. 2021-04-03 16:12:51 +02:00
Fabio Manganiello 04ff008800 Context shouldn't be dumped as json in case of exceptions - if some objects are not JSON serializable then we end up with an uncaught exception 2021-03-05 18:52:57 +01:00
Fabio Manganiello 36fdcf6963 - The context should be properly expanded also when calling a Python procedure
- Refactored the logic for executing a request and wrapping the response common to procedures, crons and event hook decorators into platypush.common.exec_wrapper

- Added mock getvalue() method to Logger to prevent PyCharm failures in the tests when sys.stdout is redirected to the Logger object
2021-02-27 20:27:36 +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 9e00428568 Don't fail silently if there were errors in parsing ${} variables or getting the context 2021-02-26 22:43:54 +01:00
Fabio Manganiello b4258faa29 Fixed broken regular expressions after LINT refactor 2021-02-26 22:33:26 +01:00
Fabio Manganiello d0a579cf4b Fixed old regex sequences to r'' format 2021-02-24 01:28:46 +01:00
Fabio Manganiello 3cf91a3f27 Fixed backend.zigbee.mqtt to work with the new zigbee2mqtt API 2021-02-11 23:50:28 +01:00
Fabio Manganiello 8a7f783032 Support for list args type in requests 2020-10-28 23:18:55 +01:00
Fabio Manganiello c269c62fe6 Refactored logging names 2020-09-27 01:33:38 +02:00
Fabio Manganiello 0dae03551f Implemented interface for custom Python scripts, procedures and hooks [closes #131] 2020-04-08 23:22:54 +02:00
Fabio Manganiello 40e65d882f Support for while/break/continue/return statemnts - closes #107 2020-01-09 10:28:02 +01:00
Fabio Manganiello d8a7c9c6e0 Added Arduino over Firmata integration - closes #92 2020-01-05 00:46:46 +01:00
Fabio Manganiello be5c5d365c Added execute tab to webpanel 2019-12-08 16:25:03 +01:00
Fabio Manganiello 92533c8303 Added special utils.get_context action to get current context 2019-12-01 17:43:10 +01:00
Fabio Manganiello 24d3810e44 Added NFC backend 2019-07-09 01:44:31 +02:00
Fabio Manganiello 0596d77403 Support for camera snapshot and stream endpoints and for disabling logging on response and event messages 2019-03-06 02:01:17 +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 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 339d1eb132 Better way to log the impacted plugin and action in case of uncaught exceptions in requests 2019-01-27 17:51:07 +01:00
Fabio Manganiello db4e68e247 Do exception logging at Request level and discard duplicate exception messages between retries 2019-01-13 20:09:25 +01:00
Fabio Manganiello 8ea0519954 Support for set/clear timeout/interval utils actions and error handling refactor
- Added set/cler timeout/interval actions in the utils plugin to
dynamically set or stop timed actions from your custom logic

- Actions error handling refactoring. If a Response is processed with
some errors, then just log the error and return it to the caller,
without raising an exception. If instead the action execution raised an
uncaught exception, then handle the retries properly and return errors
as a list with the output from all the retries, without being too
verbose with the returning and logging the whole stack trace multiple
times.
2019-01-13 19:29:08 +01:00
Fabio Manganiello 2a52eb770b Renamed value variable in expand_value_from_context to _value to prevent common name clashes with attributes named 'value' in the context 2019-01-12 22:43:01 +01:00
Fabio Manganiello 7aefe4e520 More resilient logic in case actions in a procedure return null responses 2019-01-07 00:07:45 +01:00
Fabio Manganiello 8fe4d77e3d Made requests parsing more robust against messages with target not set (e.g. messages received over HTTP API) 2018-12-18 14:59:10 +01:00
Fabio Manganiello 791c36f5df More tolerance on json.loads() in case the parsed value from the request context is not a string 2018-12-03 23:04:23 +01:00
Fabio Manganiello 4a148971b4 Allow non-string values to be passed through a request context as well 2018-12-03 22:52:25 +01:00
Fabio Manganiello 68aaf9cd61 Message timestamp refactored 2018-10-08 13:30:00 +00:00
Fabio Manganiello 948f3dc37d Implemented timestamp mark on messages to trigger message expiration logic in case something stays on the bus for longer than a minute 2018-10-08 10:35:59 +00:00
Fabio Manganiello 13c1895295 Support for runtime arguments on procedures 2018-09-25 19:20:34 +02:00
Fabio Manganiello 6449504e26 Switched the bus to a Redis bus 2018-09-20 10:49:57 +00:00
Fabio Manganiello 822e0a1e25 Better fix for broken async variables and attributes after Python 3.7 migration 2018-08-07 22:00:11 +00:00
Fabio Manganiello ee5e4dff92 Revert "In Python 3.7 async is a strict language keyword that can't be used for variables names - replaces occurrences with _async"
This reverts commit f0577733b6.
2018-08-07 21:52:07 +00:00
Fabio Manganiello b023618950 Revert "In Python 3.7 async is a strict language keyword that can't be used for variables names - replaces occurrences with _async"
This reverts commit e625861edf.
2018-08-07 21:52:02 +00:00
Fabio Manganiello f0577733b6 In Python 3.7 async is a strict language keyword that can't be used for variables names - replaces occurrences with _async 2018-08-07 21:28:06 +00:00
Fabio Manganiello e625861edf In Python 3.7 async is a strict language keyword that can't be used for variables names - replaces occurrences with _async 2018-08-07 21:26:57 +00:00
Fabio Manganiello 66d78c8615 [#61] Plugins actions refactoring
- Using `@action` annotation to indicate methods that are allowed to be
executed as actions

- The output and errors of an action are automatically wrapped into a
`Response` object without any response build required on the plugin side
2018-07-06 02:08:38 +02:00
Fabio Manganiello 81a81312e3 Basic support for token authentication on request level 2018-07-05 09:15:53 +02:00
Fabio Manganiello 061b676fbc If the string assignment didn't work either, give up without failing (also in Request) 2018-06-14 19:12:16 +02:00
Fabio Manganiello f67b737a54 Best effort in context expansion 2018-06-07 09:33:26 +02:00