def for_key(cls, key, port):

        return cls(
            None,
            key,
            port,
            current_time_stamp(),
            current_time_stamp(),
            CacheEntryStatus.loading,
            None,
            None,
            None,
            None,
        )
示例#2
0
    def for_key(cls, key, port):

        return cls(
            None,
            key,
            port,
            current_time_stamp(),
            current_time_stamp(),
            "loading",
            None,
            None,
            None,
            None,
        )
示例#3
0
def do_view(path, source_name=None):
    source = matching_source(source_name)
    match = cache.check_path(source, path)

    if match is None:
        lookup = source.lookup(path)
        if lookup is None:
            raise CellxgeneException(
                f"Could not find item for path {path} in source {source.name}",
                404,
            )
        key = CacheKey.for_lookup(source, lookup)
        print(
            f"view path={path}, source_name={source_name}, dataset={key.file_path}, annotation_file= {key.annotation_file_path}, key={key.descriptor}, source={key.source_name}"
        )
        with entry_lock:
            match = cache.check_entry(key)
            if match is None:
                uascripts = get_extra_scripts()
                match = cache.create_entry(key, uascripts)

    match.timestamp = current_time_stamp()

    if (match.status == CacheEntryStatus.loaded
            or match.status == CacheEntryStatus.loading):
        return match.serve_content(path)
    elif match.status == CacheEntryStatus.error:
        raise ProcessException.from_cache_entry(match)
示例#4
0
def main():
    logging.basicConfig(
        level=logging.INFO,
        format='%(asctime)s:%(name)s:%(levelname)s:%(message)s')
    env.validate()
    pruner = PruneProcessCache(cache)

    background_thread = Thread(target=pruner)
    background_thread.start()

    app.launchtime = current_time_stamp()
    app.run(host="0.0.0.0", port=env.gateway_port, debug=False)
def launch():
    env.validate()
    if not item_sources or not len(item_sources):
        raise Exception("No data sources specified for Cellxgene Gateway")

    global default_item_source
    if default_item_source is None:
        default_item_source = item_sources[0]

    pruner = PruneProcessCache(cache)

    background_thread = Thread(target=pruner)
    background_thread.start()

    app.launchtime = current_time_stamp()
示例#6
0
def do_view(path):
    key = get_key(path)
    print(
        f"view path={path}, dataset={key.dataset}, annotation_file= {key.annotation_file}, key={key.pathpart}"
    )
    with entry_lock:
        match = cache.check_entry(key)
        if match is None:
            uascripts = get_extra_scripts()
            match = cache.create_entry(key, uascripts)

    match.timestamp = current_time_stamp()

    if match.status == "loaded" or match.status == "loading":
        return match.serve_content(path)
    elif match.status == "error":
        raise ProcessException.from_cache_entry(match)
示例#7
0
    def prune(self):
        timestamp = util.current_time_stamp()
        cutoff = timestamp - self.expire_seconds
        processes_to_delete = [p for p in self.cache.entry_list if p.timestamp < cutoff]
        processes_to_keep = [
            p for p in self.cache.entry_list if not p.timestamp < cutoff
        ]

        logger.debug(
            f"Cutoff {cutoff} = timestamp {timestamp} - expire seconds {self.expire_seconds} , keeping {processes_to_keep}, pruning {processes_to_delete}"
        )

        for process in processes_to_delete:
            try:
                logger.info(f"pruning process {process.pid} ({process.key.dataset})")
                self.cache.prune(process)
            except Exception:
                logger.exception(
                    "failed to prune process {process.pid} ({process.dataset})"
                )