Skip to content

Commit

Permalink
remove redundant code
Browse files Browse the repository at this point in the history
Signed-off-by: Victor Garcia Reolid <victor@seita.nl>
  • Loading branch information
victorgarcia98 committed Nov 7, 2023
1 parent 814e979 commit 12d3ad8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 26 deletions.
8 changes: 0 additions & 8 deletions documentation/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -647,11 +647,3 @@ FLEXMEASURES_API_SUNSET_LINK
Allow to override the default sunset link for your clients.

Default: ``None`` (defaults are set internally for each sunset API version, e.g. ``"https://flexmeasures.readthedocs.io/en/v0.13.0/api/v2_0.html"`` for v2.0)


FLEXMEASURES_FALLBACK_REDIRECT
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Allow control over the effect of redirecting to the fallback scheduler.

Default : ``True``
36 changes: 18 additions & 18 deletions flexmeasures/api/v3_0/sensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,11 +456,14 @@ def get_schedule( # noqa: C901
if (
not current_app.config.get("FLEXMEASURES_FALLBACK_REDIRECT")
and job.is_failed
and ("fallback_job_id" in job.meta)
and (job.meta.get("fallback_job_id") is not None)
):
try: # First try the scheduling queue
job = Job.fetch(job.meta["fallback_job_id"], connection=connection)
except NoSuchJobError:
current_app.logger.error(
f"Fallback job with ID={job.meta['fallback_job_id']} (originator Job ID={job_id}) not found."
)
return unrecognized_event(job.meta["fallback_job_id"], "fallback-job")

scheduler_info_msg = ""
Expand All @@ -483,23 +486,20 @@ def get_schedule( # noqa: C901

fallback_job_id = job.meta.get("fallback_job_id")

if current_app.config.get("FLEXMEASURES_FALLBACK_REDIRECT"):
# redirect to the fallback schedule endpoint if the fallback_job_id
# is defined in the metadata of the original job
if fallback_job_id is not None:
return fallback_schedule_redirect(
message,
url_for(
"SensorAPI:get_schedule",
uuid=fallback_job_id,
id=sensor.id,
_external=True,
),
)
else:
return unknown_schedule(message)
# case that the job failed or the fallback schedule job failed (FLEXMEASURES_FALLBACK_REDIRECT = False)
return unknown_schedule(message)
# redirect to the fallback schedule endpoint if the fallback_job_id
# is defined in the metadata of the original job
if fallback_job_id is not None:
return fallback_schedule_redirect(
message,
url_for(
"SensorAPI:get_schedule",
uuid=fallback_job_id,
id=sensor.id,
_external=True,
),
)
else:
return unknown_schedule(message)

elif job.is_started:
return unknown_schedule(f"Scheduling job in progress. {scheduler_info_msg}")
Expand Down
1 change: 1 addition & 0 deletions flexmeasures/api/v3_0/tests/test_sensor_schedules.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ def test_get_schedule_fallback(
Test if the fallback job is created after a failing StorageScheduler call. This test
is based on flexmeasures/data/models/planning/tests/test_solver.py
"""
assert app.config["FLEXMEASURES_FALLBACK_REDIRECT"] is False
app.config["FLEXMEASURES_FALLBACK_REDIRECT"] = True

target_soc = 9
Expand Down

0 comments on commit 12d3ad8

Please sign in to comment.