Skip to content

Commit

Permalink
Refactor quota checking logic out of galaxy.jobs.handler.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmchilton committed Sep 11, 2020
1 parent fc44db2 commit 4975bb3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
11 changes: 2 additions & 9 deletions lib/galaxy/jobs/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
22 changes: 22 additions & 0 deletions lib/galaxy/quota/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand All @@ -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"""
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 4975bb3

Please sign in to comment.