@@ -85,25 +85,25 @@ def __get_lockkey(func, *fargs, **fkwarg
params.extend(['%s-%s' % ar for ar in fkwargs.items()])
func_name = str(func.__name__) if hasattr(func, '__name__') else str(func)
lockkey = 'task_%s.lock' % \
md5(func_name + '-' + '-'.join(map(str, params))).hexdigest()
return lockkey
def locked_task(func):
def __wrapper(func, *fargs, **fkwargs):
lockkey = __get_lockkey(func, *fargs, **fkwargs)
lockkey_path = dn(dn(dn(os.path.abspath(__file__))))
lockkey_path = config['here']
log.info('running task with lockkey %s', lockkey)
try:
l = DaemonLock(jn(lockkey_path, lockkey))
l = DaemonLock(file_=jn(lockkey_path, lockkey))
ret = func(*fargs, **fkwargs)
l.release()
return ret
except LockHeld:
log.info('LockHeld')
return 'Task with key %s already running' % lockkey
return decorator(__wrapper, func)
@@ -88,28 +88,29 @@ def whoosh_index(repo_location, full_ind
.run(full_index=full_index)
@task(ignore_result=True)
def get_commits_stats(repo_name, ts_min_y, ts_max_y):
log = get_commits_stats.get_logger()
except:
log = logging.getLogger(__name__)
lockkey = __get_lockkey('get_commits_stats', repo_name, ts_min_y,
ts_max_y)
lockkey_path = dn(dn(dn(dn(os.path.abspath(__file__)))))
lock = l = DaemonLock(jn(lockkey_path, lockkey))
lock = l = DaemonLock(file_=jn(lockkey_path, lockkey))
#for js data compatibilty cleans the key for person from '
akc = lambda k: person(k).replace('"', "")
co_day_auth_aggr = {}
commits_by_day_aggregate = {}
repos_path = get_repos_path()
repo = get_repo(safe_str(os.path.join(repos_path, repo_name)))
repo_size = len(repo.revisions)
#return if repo have no revisions
if repo_size < 1:
lock.release()
@@ -92,25 +92,25 @@ class MakeIndex(BasePasterCommand):
index_location = config['index_dir']
repo_location = self.options.repo_location \
if self.options.repo_location else RepoModel().repos_path
repo_list = map(strip, self.options.repo_list.split(',')) \
if self.options.repo_list else None
#======================================================================
# WHOOSH DAEMON
from rhodecode.lib.pidlock import LockHeld, DaemonLock
from rhodecode.lib.indexers.daemon import WhooshIndexingDaemon
l = DaemonLock(file=jn(dn(dn(index_location)), 'make_index.lock'))
l = DaemonLock(file_=jn(dn(dn(index_location)), 'make_index.lock'))
WhooshIndexingDaemon(index_location=index_location,
repo_location=repo_location,
repo_list=repo_list)\
.run(full_index=self.options.full_index)
sys.exit(1)
def update_parser(self):
self.parser.add_option('--repo-location',
action='store',
dest='repo_location',
@@ -20,35 +20,35 @@ if __platform__ in PLATFORM_WIN:
else:
kill = os.kill
class LockHeld(Exception):
pass
class DaemonLock(object):
"""daemon locking
USAGE:
l = DaemonLock(desc='test lock')
l = DaemonLock(file_='/path/tolockfile',desc='test lock')
main()
"""
def __init__(self, file=None, callbackfn=None,
def __init__(self, file_=None, callbackfn=None,
desc='daemon lock', debug=False):
self.pidfile = file if file else os.path.join(
self.pidfile = file_ if file_ else os.path.join(
os.path.dirname(__file__),
'running.lock')
self.callbackfn = callbackfn
self.desc = desc
self.debug = debug
self.held = False
#run the lock automatically !
self.lock()
self._finalize = Finalize(self, DaemonLock._on_finalize,
args=(self, debug), exitpriority=10)
@staticmethod
@@ -477,25 +477,25 @@ def create_test_index(repo_location, con
from rhodecode.lib.pidlock import DaemonLock, LockHeld
repo_location = repo_location
index_location = os.path.join(config['app_conf']['index_dir'])
if not os.path.exists(index_location):
os.makedirs(index_location)
l = DaemonLock(file=jn(dn(index_location), 'make_index.lock'))
l = DaemonLock(file_=jn(dn(index_location), 'make_index.lock'))
repo_location=repo_location)\
def create_test_env(repos_test_path, config):
"""Makes a fresh database and
install test repository into tmp dir
Status change: