Skip to content

Commit

Permalink
Redo total disk calculation adjustments to be less race condition-y.
Browse files Browse the repository at this point in the history
... at least when finishing the job. Method should probably be used other places as well.
  • Loading branch information
jmchilton authored and dannon committed Oct 12, 2015
1 parent 52d4d0e commit 4cebca8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/galaxy/jobs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1329,7 +1329,7 @@ def path_rewriter( path ):
bytes += dataset_assoc.dataset.dataset.get_total_size()

if job.user:
job.user.total_disk_usage += bytes
job.user.adjust_total_disk_usage( bytes )

# Empirically, we need to update job.user and
# job.workflow_invocation_step.workflow_invocation in separate
Expand Down
4 changes: 4 additions & 0 deletions lib/galaxy/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ def set_disk_usage( self, bytes ):

total_disk_usage = property( get_disk_usage, set_disk_usage )

def adjust_total_disk_usage( self, amount ):
from sqlalchemy import func
self.disk_usage = func.coalesce(self.table.c.disk_usage, 0) + amount

@property
def nice_total_disk_usage( self ):
"""
Expand Down
11 changes: 11 additions & 0 deletions test/unit/test_galaxy_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,17 @@ def test_collections_in_library_folders(self):
# self.assertEquals(len(loaded_dataset_collection.datasets), 2)
# assert loaded_dataset_collection.collection_type == "pair"

def test_default_disk_usage( self ):
model = self.model

u = model.User( email="disk_default@test.com", password="password" )
self.persist( u )
u.adjust_total_disk_usage( 1 )
u_id = u.id
self.expunge()
user_reload = model.session.query( model.User ).get( u_id )
assert user_reload.disk_usage == 1

def test_basic( self ):
model = self.model

Expand Down

0 comments on commit 4cebca8

Please sign in to comment.