From 4975bb34ef5cc2c42a7a5beaa9cfc27fc599e3ab Mon Sep 17 00:00:00 2001 From: John Chilton Date: Fri, 11 Sep 2020 15:31:13 -0400 Subject: [PATCH] Refactor quota checking logic out of galaxy.jobs.handler. --- lib/galaxy/jobs/handler.py | 11 ++--------- lib/galaxy/quota/__init__.py | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/lib/galaxy/jobs/handler.py b/lib/galaxy/jobs/handler.py index 1d309bbb458c..db4c3e719b6e 100644 --- a/lib/galaxy/jobs/handler.py +++ b/lib/galaxy/jobs/handler.py @@ -558,15 +558,8 @@ def __verify_job_ready(self, job, job_wrapper): if state == JOB_READY: state = self.__check_user_jobs(job, job_wrapper) - if state == JOB_READY and self.app.config.enable_quotas: - quota = self.app.quota_agent.get_quota(job.user) - if quota is not None: - try: - usage = self.app.quota_agent.get_usage(user=job.user, history=job.history) - if usage > quota: - return JOB_USER_OVER_QUOTA, job_destination - except AssertionError: - pass # No history, should not happen with an anon user + if state == JOB_READY and self.app.quota_agent.is_over_quota(job, job_destination): + return JOB_USER_OVER_QUOTA, job_destination # Check total walltime limits if (state == JOB_READY and "delta" in self.app.job_config.limits.total_walltime): diff --git a/lib/galaxy/quota/__init__.py b/lib/galaxy/quota/__init__.py index 549fa8af7b98..9202ce7282fd 100644 --- a/lib/galaxy/quota/__init__.py +++ b/lib/galaxy/quota/__init__.py @@ -50,6 +50,14 @@ def get_usage(self, trans=None, user=False, history=False): usage = user.total_disk_usage return usage + def is_over_quota(self, job, job_destination): + """Return True if the user or history is over quota for specified job. + + job_destination unused currently but an important future application will + be admins and/or users dynamically specifying which object stores to use + and that will likely come in through the job destination. + """ + class NoQuotaAgent(QuotaAgent): """Base quota agent, always returns no quota""" @@ -67,6 +75,9 @@ def default_quota(self): def get_percent(self, trans=None, user=False, history=False, usage=False, quota=False): return None + def is_over_quota(self, job, job_destination): + return False + class DatabaseQuotaAgent(QuotaAgent): """Class that handles galaxy quotas""" @@ -205,6 +216,17 @@ def set_entity_quota_associations(self, quotas=None, users=None, groups=None, de self.sa_session.add(gqa) self.sa_session.flush() + def is_over_quota(self, job, job_destination): + quota = self.get_quota(job.user) + if quota is not None: + try: + usage = self.get_usage(user=job.user, history=job.history) + if usage > quota: + return True + except AssertionError: + pass # No history, should not happen with an anon user + return False + def get_quota_agent(config, model): if config.enable_quotas: