Skip to content

Commit

Permalink
Merge branch 'main' into coveralls-new-gh-action
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas Höning <nicolas@seita.nl>
  • Loading branch information
nhoening committed Jul 13, 2023
2 parents 7a12cd9 + 5508b8c commit a112765
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 16 deletions.
25 changes: 13 additions & 12 deletions .github/workflows/lint-and-test.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
name: lint-and-test

on: ["push", "pull_request"]

on:
push:
pull_request:
types:
- opened
jobs:
check:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -35,7 +38,8 @@ jobs:
run: |
git fetch --prune --unshallow
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
- uses: actions/cache@v2
- name: "Caching dependencies (txt)"
uses: actions/cache@v2
id: cache
with:
path: ${{ env.pythonLocation }}
Expand All @@ -46,17 +50,14 @@ jobs:
- run: |
ci/setup-postgres.sh
sudo apt-get -y install coinor-cbc
- name: Install FlexMeasures & dependencies for tests
if: steps.cache.outputs.cache-hit != 'true'
run: |
make install-pip-tools
make install-for-test
- name: Run all tests except those marked to be skipped by GitHub
run: pytest -m "not skip_github"
if: ${{ matrix.coverage != 'yes' }}
- name: Install FlexMeasures & exact dependencies for tests
run: make install-for-test
if: github.event_name == 'push' && steps.cache.outputs.cache-hit != 'true'
- name: Install FlexMeasures & latest dependencies for tests
run: make install-for-test pinned=no
if: github.event_name == 'pull_request'
- name: Run all tests except those marked to be skipped by GitHub AND record coverage
run: pytest -v -m "not skip_github" --cov=flexmeasures --cov-branch --cov-report=lcov
if: ${{ matrix.coverage == 'yes' }}
- name: Coveralls
uses: coverallsapp/github-action@v2
if: ${{ matrix.coverage == 'yes' }}
Expand Down
18 changes: 16 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Note: use tabs
# actions which are virtual, i.e. not a script
.PHONY: install install-for-dev install-deps install-flexmeasures run-local test freeze-deps upgrade-deps update-docs update-docs-pdf show-file-space show-data-model clean-db
.PHONY: install install-for-dev install-for-test install-deps install-flexmeasures run-local test freeze-deps upgrade-deps update-docs update-docs-pdf show-file-space show-data-model clean-db


# ---- Development ---
Expand Down Expand Up @@ -39,13 +39,27 @@ install-for-dev:
make install-flexmeasures

install-for-test:
pip-sync requirements/app.txt requirements/dev.txt requirements/test.txt
make install-pip-tools
# Pass pinned=no if you want to test against latest stable packages, default is our pinned dependency set
ifneq ($(pinned), no)
pip-sync requirements/app.txt requirements/test.txt
else
# cutting off the -c inter-layer dependency (that's pip-tools specific)
tail -n +3 requirements/test.in >> temp-test.in
pip install --upgrade -r requirements/app.in -r temp-test.in
rm temp-test.in
endif
make install-flexmeasures

install-deps:
make install-pip-tools
make freeze-deps
# Pass pinned=no if you want to test against latest stable packages, default is our pinned dependency set
ifneq ($(pinned), no)
pip-sync requirements/app.txt
else
pip install --upgrade -r requirements/app.in
endif

install-flexmeasures:
pip install -e .
Expand Down
1 change: 1 addition & 0 deletions documentation/api/change_log.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ v3.0-10 | 2023-06-12
""""""""""""""""""""

- Introduced the ``storage-efficiency`` field to the ``flex-model``field for `/sensors/<id>/schedules/trigger` (POST).
- Introduced the ``database_redis`` optional field to the response of the endpoint `/health/ready` (GET).

v3.0-9 | 2023-04-26
"""""""""""""""""""
Expand Down
3 changes: 3 additions & 0 deletions documentation/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ Infrastructure / Support
----------------------

* Add support for profiling Flask API calls using ``pyinstrument`` (if installed). Can be enabled by setting the environment variable ``FLEXMEASURES_PROFILE_REQUESTS`` to ``True`` [see `PR #722 <https://www.github.com/FlexMeasures/flexmeasures/pull/722>`_]
* The endpoint `[POST] /health/ready <api/v3_0.html#get--api-v3_0-health-ready>`_ returns the status of the Redis connection, if configured [see `PR #699 <https://www.github.com/FlexMeasures/flexmeasures/pull/699>`_]


/api/v3_0/health/ready

v0.14.1 | June 26, 2023
============================

Expand Down
26 changes: 24 additions & 2 deletions flexmeasures/api/v3_0/health.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from flask_classful import FlaskView, route
from flask_json import as_json


from redis.exceptions import ConnectionError
from flexmeasures.data import db


Expand All @@ -14,6 +16,18 @@ def _check_sql_database():
return False


def _check_redis() -> bool:
"""Check status of the redis instance
:return: True if the redis instance is active, False otherwise
"""
try:
current_app.redis_connection.ping()
return True
except ConnectionError:
return False


class HealthAPI(FlaskView):

route_base = "/health"
Expand All @@ -32,11 +46,19 @@ def is_ready(self):
.. sourcecode:: json
{
'database_sql': True
'database_sql': True,
'database_redis': False
}
"""
status = {"database_sql": _check_sql_database()} # TODO: check redis

status = {
"database_sql": _check_sql_database(),
}

if current_app.config.get("FLEXMEASURES_REDIS_PASSWORD") is not None:
status["database_redis"] = _check_redis()

if all(status.values()):
return status, 200
else:
Expand Down

0 comments on commit a112765

Please sign in to comment.