Handle group options for concurrency and throttle separately

This commit is contained in:
Stefan Agner 2025-07-10 15:08:21 +02:00
parent d95048ed60
commit 24a65dccd5
No known key found for this signature in database
GPG Key ID: AE01353D1E44747D

View File

@ -239,15 +239,22 @@ class Job(CoreSysAttributes):
job_group = cast(JobGroup, obj) job_group = cast(JobGroup, obj)
# Check for group-based parameters # Check for group-based parameters
group_based_params = [ if not job_group:
self.concurrency if self.concurrency in (
in (JobConcurrency.GROUP_REJECT, JobConcurrency.GROUP_QUEUE), JobConcurrency.GROUP_REJECT,
self.throttle in (JobThrottle.GROUP_THROTTLE, JobThrottle.GROUP_RATE_LIMIT), JobConcurrency.GROUP_QUEUE,
] ):
if not job_group and any(group_based_params):
raise RuntimeError( raise RuntimeError(
f"Job on {self.name} need to be a JobGroup to use group based limits!" f"Job {self.name} uses group concurrency ({self.concurrency}) but is not on a JobGroup! "
f"The class must inherit from JobGroup to use GROUP_REJECT or GROUP_QUEUE."
) from None
if self.throttle in (
JobThrottle.GROUP_THROTTLE,
JobThrottle.GROUP_RATE_LIMIT,
):
raise RuntimeError(
f"Job {self.name} uses group throttling ({self.throttle}) but is not on a JobGroup! "
f"The class must inherit from JobGroup to use GROUP_THROTTLE or GROUP_RATE_LIMIT."
) from None ) from None
return job_group return job_group