Skip to content

feat: add custom job timeouts, also configurable per queue#2318

Open
nhoening wants to merge 13 commits into
mainfrom
feat/job-timeout
Open

feat: add custom job timeouts, also configurable per queue#2318
nhoening wants to merge 13 commits into
mainfrom
feat/job-timeout

Conversation

@nhoening

@nhoening nhoening commented Jul 14, 2026

Copy link
Copy Markdown
Member

Description

Hosts might want to increase the default timeout altogether (for slower hardware), or even per queue. This PR adds 2 config settings to do that.

Closes #2227

  • add & apply two config settings
  • Added changelog item in documentation/changelog.rst

How to test

Run flexmeasures/utils/job_utils.py

Notes

I found that there was a timeout setting for forecasts, in a rather obscure manner inside the code, giving forecasts 1 hour instead of 3 minutes.
So in that sense this PR is not completely backwards-compatible. @BelhsanHmida maybe you can comment on that.

Signed-off-by: Nicolas Höning <nicolas@seita.nl>
@nhoening
nhoening requested a review from BelhsanHmida July 14, 2026 16:31
@nhoening nhoening added this to the 1.0.0 milestone Jul 14, 2026
@nhoening nhoening self-assigned this Jul 14, 2026
@nhoening nhoening added the jobs label Jul 14, 2026
Signed-off-by: Nicolas Höning <nicolas@seita.nl>
@read-the-docs-community

read-the-docs-community Bot commented Jul 14, 2026

Copy link
Copy Markdown

Keep the built-in forecasting queue timeout at one hour while the global default remains 180 seconds.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Log an error when job timeout configuration names a queue that FlexMeasures does not create.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Cover the preserved forecasting default, global default overrides, and unknown timeout queue logging.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Document the supported timeout queue names and the default forecasting queue timeout.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Mention that the new timeout settings preserve the one-hour forecasting default.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>

@BelhsanHmida BelhsanHmida left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me now.

I added some small follow-up commits to preserve backwards compatibility with forecasting and make the config safer:

  • kept forecasting jobs on the existing 1-hour default timeout
  • added an error log for unknown queue names like "forecast"
  • covered the built-in defaults, global defaults, queue overrides, and typo handling in tests
  • add small docs mention for forecasting default

I also manually tested this. Results matched expectations:

  • built-in defaults: forecasting 3600s, scheduling/ingestion 180s
  • custom global PT5M plus forecasting PT1H: forecasting 3600s, scheduling/ingestion 300s
  • typoed queue key "forecast": logs an error and falls back to the global default

@nhoening

nhoening commented Jul 15, 2026

Copy link
Copy Markdown
Member Author

1 hour is a lot though.
This can lead to clogged queues. Can you motivate that?

@Flix6x

Flix6x commented Jul 15, 2026

Copy link
Copy Markdown
Member

I don't think 1-hour forecasting jobs are defensible or needed in a live ems. Maybe in simulation, where they do a batch operation on years, but even that is parallelized by now, with afaik separate jobs either per vantage point (belief time) or per retraining frequency (so the same trained model gets reused for a few different vantage points with the job. In practice 5 minutes ought to be enough and should also be a practical limit, indeed to prevent clogging up the queue.

And of course the whole point of this PR is that (e.g. simulation) users can easily customize the timeout now.

@BelhsanHmida

Copy link
Copy Markdown
Contributor

My thinking around the 1-hour default was mostly based on simulation forecasting jobs, where jobs used to keep timing out. We solved much of that with parallelization per retraining cycle, so I agree that a 1-hour timeout is too generous as a default. You are both correct to point out that it can clog live EMS queues.

So I think the regular default timeout is the better practical limit. For cases like simulations or slower hosts, users can now explicitly configure a longer timeout with FLEXMEASURES_JOB_TIMEOUT or FLEXMEASURES_DEFAULT_JOB_TIMEOUT.

One follow-up from that discussion is that timeout failures should be actionable: if a forecasting job times out, we should log clearly that it timed out and suggest either reducing the forecasting parameters/workload or increasing the timeout config.

BelhsanHmida and others added 6 commits July 15, 2026 14:23
Let forecasting use the global RQ job timeout unless hosts configure a queue override.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Record and log an actionable hint when a forecasting job fails due to an RQ timeout.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Expect forecasting queues to inherit the global timeout by default.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Assert timeout failures log and persist a configuration hint on forecasting jobs.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Document the neutral per-queue timeout default and timeout guidance behavior.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <149331360+BelhsanHmida@users.noreply.github.com>
@BelhsanHmida

Copy link
Copy Markdown
Contributor

I pushed the follow-up to keep forecasting on the regular default timeout of 3 minutes, instead of preserving the old 1-hour timeout.

I also added an actionable timeout message for forecasting jobs. If a forecasting job times out, we now log a hint and store it in the failed job metadata, suggesting splitting the forecast request, reducing max-forecast-horizon / forecast cycles, or configuring a longer FLEXMEASURES_JOB_TIMEOUT for the forecasting queue.

FORECASTING_JOB_TIMEOUT_HINT = (
"Forecasting job timed out. Try splitting the forecast request into smaller "
"periods, reducing the prediction window by lowering `max-forecast-horizon`, "
"using fewer forecast cycles via `forecast-frequency`, or increasing "

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the user use more forecast cycles by setting the forecast-frequency to smaller timedelta?

This comment is actually 3 notes in one:

  1. More cycles leads to more jobs, but it leads to shorter runtime per job. Fewer cycles would most likely increase the runtime, I think.
  2. Minor thing: the backticks around the field name are very unlikely to show up as a code snippet to the API user.
  3. A "lower frequency" is ambiguous. FlexMeasures follows Pandas terminology on this topic, which defines the frequency as a time unit, whereas it is actually one over time. That is, a low frequency normally would have a long duration between ticks. This is why I prefer explicitly mentioning what should happen to the timedelta instead.

if isinstance(exc_type, type) and issubclass(exc_type, JobTimeoutException):
logger = logging.getLogger(__name__)
logger.warning(FORECASTING_JOB_TIMEOUT_HINT)
click.echo(FORECASTING_JOB_TIMEOUT_HINT)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one should probably go.

"Forecasting job timed out. Try splitting the forecast request into smaller "
"periods, reducing the prediction window by lowering `max-forecast-horizon`, "
"using fewer forecast cycles via `forecast-frequency`, or increasing "
"FLEXMEASURES_JOB_TIMEOUT for the `forecasting` queue."

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would show this hint only in the log statement for hosts and not in the API user hint.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FLEXMEASURES_JOB_TIMEOUT

3 participants