Commit graph

33 commits

Author SHA1 Message Date
fusion44
a9bbc9a27c
fix(api): release Redis connections in channel listeners/notifiers
Some checks failed
CodeQL / Analyze (actions) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
BaseChannelListener.listen() only called pubsub.unsubscribe() in its
finally block: the pubsub connection and the listener's own Redis client
were never released, leaking a connection for every install/uninstall
(_watcher) and every recreation of the app-status listener. The Celery
task notifiers were likewise never closed, and used the deprecated
Redis.close() instead of aclose().

- add aclose() to BaseChannelNotifier and BaseChannelListener
- listen() now closes the pubsub and its Redis client in finally
- close the notifiers in the app_manage / app_status_update tasks and
  switch to aclose()
- back off in the app-status watch loop so a Redis outage no longer
  spins, and drop a leftover debug print

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-03 22:40:14 +02:00
fusion44
868457ffa5
fix(api): replace deprecated asyncio.get_event_loop()
get_event_loop() is deprecated on Python 3.11+ when there is no running
loop and is slated to change behaviour further.

- SSEManager.setup() ran at import time (app.api.utils) via
  get_event_loop(); this only worked because uvicorn imports the app
  inside its loop and would break when imported without a running loop
  (e.g. a Celery worker). Start the broadcast consumer lazily from
  within a running loop instead.
- everywhere else the pattern was get_event_loop().create_task(x)
  inside a coroutine; replace with asyncio.create_task(x).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-03 22:34:44 +02:00
fusion44
ff54f93397
fix(api): catch subprocess timeouts in exec_bash_command
'from redis.asyncio import ... TimeoutError' shadowed the builtin
TimeoutError. redis's TimeoutError is a RedisError subclass, not a
builtin subclass, so the 'except TimeoutError' guarding
asyncio.wait_for never matched: timed-out commands fell through to the
generic handler, the child process was never terminated (leak), and
the caller got a misleading 'unable to execute' error instead of a
timeout.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-03 19:59:57 +02:00
fusion44
49d5fcb9bf
fix: send bitcoin-only warmup app status as app_state_update_message
The WebUI only listens for the app_state_update_message SSE event to
populate the Apps tab. In bitcoin-only mode the warmup data was sent
under installed_app_status, which no client listens to, so the Apps
tab was stuck on the loading screen whenever the app status cache was
warm. Installing LND made it work again because the lightning warmup
path already used the correct event (raspiblitz#3608, raspiblitz#5141).

Also hardens the warmup path:
- reset the warmup_running flag on errors so a single failure no
  longer starves all future SSE clients of warmup data
- convert per-source exceptions in the bitcoin-only warmup gather
  instead of discarding the whole data set
- don't fall through to the partial-data branches when the API is
  fully initialized with lightning disabled
- remove the now-unused INSTALLED_APP_STATUS event and the dead
  cached_status_raw variable

Adds regression tests plus a conftest.py providing test env defaults
so the suite runs without a developer .env file.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-03 15:30:17 +02:00
fusion44
e564d18d2b
chore: clean up imports; add better LND error logging 2026-02-03 11:05:19 +01:00
fusion44
07d2bfbc76
feat: update Python and Devenv deps
- Updated all dependencies to their latest versions
- Vendored fastapi-plugins[redis] as it looks unmaintained
2026-02-03 11:04:41 +01:00
fusion44
b555466053
fix: increase timeout for fetching app statuses 2025-08-08 18:27:48 +02:00
fusion44
d63e63f4e6
chore: remove deprecated async-timeout dep use 2025-05-13 19:22:47 +02:00
fusion44
f1aa2107fd refactor: code cleanup
- rename various keys
- update app status updater code to work like the app management code
- remove some unused code

refs #123
2025-05-06 09:16:46 +02:00
fusion44
1f491ed0a0 feat: implement (un)install celery task
refs #123
2025-05-06 09:16:46 +02:00
fusion44
de1594f7e4 refactor: nicer layout for app status cache code 2025-05-06 09:16:46 +02:00
fusion44
6bd875f16b refactor: move app update code into its own file 2025-05-06 09:16:46 +02:00
fusion44
824fa62c4d chore: small fixes and updates
- formatting
- small fix in a bitcoind model
- update the fake blitz scripts
- remove some dead code (app status sub)
2025-05-06 09:16:46 +02:00
fusion44
4e038e8fc7 feat: fetch app status via a celery task
This is a feature that allows to fetch the app status via a celery
task which stores the result in the Redis database and notifies the API
of the change. The API sends a notification to connected clients via the
SSE mechanism.

Using a background task allows to avoid crashing the whole API if the
script call fails.

The by default the cache is refreshed every 30 minutes. This can be
changed by setting the `BAPI_APP_STATUS_UPDATE_INTERVAL_MIN` environment
variable.

refs #123
2025-05-06 09:16:46 +02:00
fusion44
4a70d2ca36 feat: add error handling to get_redis helper func
refs #123
2025-05-06 09:16:46 +02:00
fusion44
2b98912796 feat: replace call_script func with better func
use exec_bash_command instead

refs #123
2025-05-06 09:16:46 +02:00
fusion44
751687e60b chore: run ruff format and isort 2025-05-06 09:16:46 +02:00
fusion44
691d5da6b9 feat: update formatting of errors sent to clients
refs #123
2025-05-06 09:16:46 +02:00
fusion44
ef9bfbefe4 feat: add supporting types for error handling
- add a result type similar to the Rust Result type from
https://github.com/rustedpy/result
- add a Report class to propagate error information back on the stack
with return types instead of exceptions

refs #123
2025-05-06 09:16:46 +02:00
fusion44
25e4be8441 feat: make config loading more flexible
If the environment variable BAPI_ENV_PATH is set, the config system will
try to read configs from the given path instead of .env in pwd

If no file is found .env in pwd will be used as a fallback

Env variables will always override settings in .env files.
2025-03-23 17:43:39 +01:00
pre-commit-ci[bot]
0c73b78f47 [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2024-10-06 14:18:01 +02:00
Christoph Stenglein
cf4ab3963c remove ln_info_lite 2024-10-06 14:18:01 +02:00
fusion44
adf472ac8b feat: implement Ruff as a linter; fix given errors 2023-06-25 07:17:00 +02:00
fusion44
71ad84e704
feat: improve logging and error handling 2023-04-21 22:58:29 +02:00
fusion44
98b5912b23
feat: improve logging and error handling
* SSE client warmup data now logs errors properly
* apps module now logs errors properly
2023-04-02 11:09:43 +02:00
pre-commit-ci[bot]
3d1dfd919c
[pre-commit.ci] pre-commit autoupdate (#187)
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/psf/black: 22.12.0 → 23.1.0](https://github.com/psf/black/compare/22.12.0...23.1.0)

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-02-11 13:47:34 +01:00
fusion44
0fe94da897
feat: prepare for release 0.5.1beta 2023-02-05 21:24:31 +01:00
fusion44
5c61c2f942
chore: remove unused import and run pre-commit 2022-12-01 19:14:01 +01:00
fusion44
3ab007138e
fix: reactivate app status in warmup data
refs #157
2022-10-22 11:09:19 +02:00
fusion44
04eadf9caa
chore: add changes from main
Due to the heavy refactoring work, it was almost impossible to
normally merge the changes over. The changes where applied
by manually.
2022-10-20 20:38:47 +02:00
fusion44
fe65568f55
Revert "chore: merge changes from main"
This reverts commit e3f0350c72, reversing
changes made to a448dbda8d.
2022-10-19 21:32:47 +02:00
fusion44
e3f0350c72
chore: merge changes from main 2022-10-19 21:19:43 +02:00
fusion44
ba453e7bdb
refactor: switch to domain driven directory layout 2022-10-03 20:22:00 +02:00