Changeset - 9bedaa073c23
[Not reviewed]
default
0 2 0
Marcin Kuzminski - 15 years ago 2010-09-28 22:07:55
marcin@python-works.com
fixed lockdecrator to return executed function data
removed print
2 files changed with 2 insertions and 2 deletions:
0 comments (0 inline, 0 general)
pylons_app/controllers/summary.py
Show inline comments
 
@@ -74,32 +74,31 @@ class SummaryController(BaseController):
 
                            d, 0, 0, 0, 0, 0, 0,))
 
        ts_min_m = mktime((y, (td - timedelta(days=calendar.mdays[m])).month,
 
                            d, 0, 0, 0, 0, 0, 0,))
 
        
 
        ts_max_y = mktime((y, m, d, 0, 0, 0, 0, 0, 0,))
 
            
 
        run_task(get_commits_stats, c.repo_info.name, ts_min_y, ts_max_y)
 
        c.ts_min = ts_min_m
 
        c.ts_max = ts_max_y
 
        
 
        stats = self.sa.query(Statistics)\
 
            .filter(Statistics.repository == c.repo_info.dbrepo)\
 
            .scalar()
 
        
 
        
 
        if stats and stats.languages:
 
            lang_stats = json.loads(stats.languages)
 
            c.commit_data = stats.commit_activity
 
            c.overview_data = stats.commit_activity_combined
 
            c.trending_languages = json.dumps(OrderedDict(
 
                                       sorted(lang_stats.items(), reverse=True,
 
                                            key=lambda k: k[1])[:2]
 
                                        )
 
                                    )
 
            print c.trending_languages
 
        else:
 
            c.commit_data = json.dumps({})
 
            c.overview_data = json.dumps([[ts_min_y, 0], [ts_max_y, 0] ])
 
            c.trending_languages = json.dumps({})
 
        
 
        return render('summary/summary.html')
 

	
pylons_app/lib/celerylib/__init__.py
Show inline comments
 
@@ -21,39 +21,40 @@ def run_task(task, *args, **kwargs):
 
        t = task.delay(*args, **kwargs)
 
        log.info('running task %s', t.task_id)
 
        return t
 
    except Exception, e:
 
        print e
 
        if e.errno == 111:
 
            log.debug('Unnable to connect. Sync execution')
 
        else:
 
            log.error(traceback.format_exc())
 
        #pure sync version
 
        return ResultWrapper(task(*args, **kwargs))
 

	
 

	
 
def locked_task(func):
 
    def __wrapper(func, *fargs, **fkwargs):
 
        params = list(fargs)
 
        params.extend(['%s-%s' % ar for ar in fkwargs.items()])
 
            
 
        lockkey = 'task_%s' % \
 
            md5(str(func.__name__) + '-' + \
 
                '-'.join(map(str, params))).hexdigest()
 
        log.info('running task with lockkey %s', lockkey)
 
        try:
 
            l = DaemonLock(lockkey)
 
            func(*fargs, **fkwargs)
 
            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)      
 
            
 

	
 
        
 
        
 
    
 
    
 
    
 
  
0 comments (0 inline, 0 general)