Пример #1
0
def next_repo( queue, local=False ):
    """Gets next collection_path or time til next ready to be updated
        
    @param queue: 
    @param local: Boolean Use local per-collection locks or global lock.
    @returns: collection_path or (msg,timedelta)
    """
    collection_path = None
    message = None
    next_available = None
    # sorts collections in ascending order by timestamp
    collections = sorted(queue['collections'])
    # now choose
    if local:
        # choose first collection that is not locked
        for timestamp,cid in collections:
            if datetime.now() > timestamp:
                cpath = os.path.join(settings.MEDIA_BASE, cid)
                collection = Collection.from_json(cpath)
                if not collection.locked():
                    collection_path = cpath
                    return collection_path
            if (not next_available) or (timestamp < next_available):
                next_available = timestamp
    else:
        # global lock - just take the first collection
        for timestamp,cid in collections:
            if datetime.now() > timestamp:
                collection_path = os.path.join(settings.MEDIA_BASE, cid)
                return collection_path
            if (not next_available) or (timestamp < next_available):
                next_available = timestamp
    return ('notready',next_available)