Skip to content

Commit

Permalink
Refactor sleeper duplications
Browse files Browse the repository at this point in the history
  • Loading branch information
hexylena committed Sep 3, 2015
1 parent b0f2eae commit 5415e29
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 40 deletions.
20 changes: 1 addition & 19 deletions lib/galaxy/jobs/deferred/__init__.py
Expand Up @@ -8,6 +8,7 @@

from galaxy import model
from galaxy.util.bunch import Bunch
from galaxy.util.sleeper import Sleeper

log = logging.getLogger( __name__ )

Expand Down Expand Up @@ -148,25 +149,6 @@ def shutdown( self ):
self.sleeper.wake()


class Sleeper( object ):
"""
Provides a 'sleep' method that sleeps for a number of seconds *unless*
the notify method is called (from a different thread).
"""
def __init__( self ):
self.condition = threading.Condition()

def sleep( self, seconds ):
self.condition.acquire()
self.condition.wait( seconds )
self.condition.release()

def wake( self ):
self.condition.acquire()
self.condition.notify()
self.condition.release()


class FakeTrans( object ):
"""A fake trans for calling the external set metadata tool"""
def __init__( self, app, history=None, user=None):
Expand Down
23 changes: 2 additions & 21 deletions lib/galaxy/jobs/transfer_manager.py
Expand Up @@ -8,7 +8,7 @@
import socket
import threading

from galaxy.util import listify, json
from galaxy.util import listify, json, sleeper

log = logging.getLogger( __name__ )

Expand All @@ -24,7 +24,7 @@ def __init__( self, app ):
if app.config.get_bool( 'enable_job_recovery', True ):
# Only one Galaxy server process should be able to recover jobs! (otherwise you'll have nasty race conditions)
self.running = True
self.sleeper = Sleeper()
self.sleeper = sleeper.Sleeper()
self.restarter = threading.Thread( target=self.__restarter )
self.restarter.start()

Expand Down Expand Up @@ -155,22 +155,3 @@ def __restarter( self ):
def shutdown( self ):
self.running = False
self.sleeper.wake()


class Sleeper( object ):
"""
Provides a 'sleep' method that sleeps for a number of seconds *unless*
the notify method is called (from a different thread).
"""
def __init__( self ):
self.condition = threading.Condition()

def sleep( self, seconds ):
self.condition.acquire()
self.condition.wait( seconds )
self.condition.release()

def wake( self ):
self.condition.acquire()
self.condition.notify()
self.condition.release()

0 comments on commit 5415e29

Please sign in to comment.