Skip to content

Commit

Permalink
Quota deletion working
Browse files Browse the repository at this point in the history
  • Loading branch information
pierotofy committed Sep 4, 2023
1 parent aa737da commit 1b92ee1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/static/app/css/sb-admin-2.css
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ body {
}

.navbar-top-links .dropdown-menu li div.info-item.quotas{
min-width: 190px;
min-width: 232px;
}

.navbar-top-links .dropdown-menu li .progress{
Expand Down
2 changes: 1 addition & 1 deletion app/templatetags/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def quota_exceeded_grace_period(context):
return _("within %(num)s days") % {"num": math.ceil(diff / (60*60*24))}
elif diff >= 60*60:
return _("within %(num)s hours") % {"num": math.ceil(diff / (60*60))}
elif diff > 0:
elif diff > 1:
return _("within %(num)s minutes") % {"num": math.ceil(diff / 60)}
else:
return _("very soon")
Expand Down
32 changes: 23 additions & 9 deletions worker/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,26 @@ def export_pointcloud(self, input, **opts):
@app.task
def check_quotas():
profiles = Profile.objects.filter(quota__gt=-1)
# for p in profiles:
# deadline_key = "%s_quota_exceeded_deadline" % p.user.id

# if p.has_exceeded_quota():
# now = time.time()
# deadline = redis_client.getset(deadline_key, now + (settings.QUOTA_EXCEEDED_GRACE_PERIOD * 60 * 60))
# # if deadline < now: TODO..
# else:
# redis_client.delete(deadline_key)
for p in profiles:
if p.has_exceeded_quota():
deadline = p.get_quota_deadline()
if deadline is None:
deadline = p.set_quota_deadline(settings.QUOTA_EXCEEDED_GRACE_PERIOD)
now = time.time()
if now > deadline:
# deadline passed, delete tasks until quota is met
logger.info("Quota deadline expired for %s, deleting tasks" % str(p.user.username))

while p.has_exceeded_quota():
try:
last_task = Task.objects.filter(project__owner=p.user).order_by("-created_at").first()
if last_task is None:
break
logger.info("Deleting %s" % last_task)
last_task.delete()
except Exception as e:
logger.warn("Cannot delete %s for %s: %s" % (str(last_task), str(p.user.username), str(e)))
break
else:
p.clear_quota_deadline()

0 comments on commit 1b92ee1

Please sign in to comment.