Feat/integrate reporting api hems - #224
Draft
BelhsanHmida wants to merge 12 commits into
Draft
Conversation
Background jobs polled via the generic jobs API can end in a failed terminal state or never reach one at all. Give both cases a dedicated exception so callers can tell them apart from transport errors. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Add get_job_status() for a single lookup of GET /api/v3_0/jobs/<uuid>, and wait_for_job() to poll one until it reaches a terminal state, with exponential backoff capped at max_polling_interval and a total timeout budget. Failed jobs raise JobFailedError carrying the server's message and traceback, so callers get something actionable instead of a bare status. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Add trigger_report(), posting to POST /assets/<id>/reports/trigger and returning the queued job UUID, plus trigger_and_await_report() which chains it with wait_for_job(). The endpoint lands in FlexMeasures v1.1.0, so a 404 from an older server is reported as a version problem pointing at the CLI fallback. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Assert the exact request bodies sent to the trigger endpoint, that polling walks through QUEUED/DEFERRED/STARTED before returning a finished job, and that failed, stopped, canceled and never-finishing jobs each raise the right error. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Replace run_report_cmd() and its subprocess call with an async run_report() that triggers the report on the asset owning its output sensors and waits for the job. Parameters are now built in memory rather than written to configs/*_reporter_param.json, and configs are read on the client side and posted along with the request. Neither the CLI nor a bind-mount of configs/ into the server is needed anymore, so cli_command_prefix() and the FLEXMEASURES_CLI_CMD/FLEXMEASURES_CLI_CONFIG_DIR handling are gone. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Drop the 'which flexmeasures' probe that silently skipped report generation, and call run_report() per site instead of writing parameter files and shelling out. Also carry the per-site outcome into the return value, which previously reflected the last site only. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Sensors nested in an asset listing are dumped with only id and name, so deriving the asset from an output sensor fails for anything read that way. Add an asset_id override to run_report() and a clear error when derivation is not possible. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Make run_community_aggregate async and route both the per-site and the community aggregate through run_report(). Awaiting each job in turn keeps the ordering the community report depends on, and the community report is now skipped outright when a site aggregate did not finish, rather than silently aggregating stale data. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Note the v1.1.0 server requirement, add reporting to the worker queues, and replace the CLI workaround section, which no longer applies now that report configuration is posted rather than read from disk by the server. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Reporter parameters are built in memory now, so nothing writes configs/*_reporter_param.json anymore. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Mirror the forecasting page: endpoints and server requirement, which asset a report is triggered against, the polling knobs, and what JobFailedError and JobTimeoutError each mean. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Assert that reports are scoped to the asset owning their output sensors, that mixed-asset and asset-less outputs are refused, that parameters and configs come out as the reporters expect, and that no HEMS module shells out anymore. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Coverage Report for CI Build 32161932884Coverage increased (+0.03%) to 96.612%Details
Uncovered Changes
Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Replaces the HEMS example's
flexmeasures add reportsubprocess calls with the report-job API, and adds the client methods that make that possible.Closes #223.
trigger_report()forPOST /assets/<id>/reports/trigger, returning the queued job UUIDget_job_status()/wait_for_job()for pollingGET /jobs/<uuid>with bounded backoff, plustrigger_and_await_report()chaining bothJobFailedErrorandJobTimeoutErrorreportingworker queue and the minimum server version