本文整理汇总了Python中totalimpact.providers.provider.ProviderFactory.num_providers_with_metrics方法的典型用法代码示例。如果您正苦于以下问题:Python ProviderFactory.num_providers_with_metrics方法的具体用法?Python ProviderFactory.num_providers_with_metrics怎么用?Python ProviderFactory.num_providers_with_metrics使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类totalimpact.providers.provider.ProviderFactory
的用法示例。
在下文中一共展示了ProviderFactory.num_providers_with_metrics方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: collection_update
# 需要导入模块: from totalimpact.providers.provider import ProviderFactory [as 别名]
# 或者: from totalimpact.providers.provider.ProviderFactory import num_providers_with_metrics [as 别名]
def collection_update(cid=""):
# first, get the tiids in this collection:
try:
collection = mydao.get(cid)
tiids = collection["alias_tiids"].values()
except Exception:
logger.exception("couldn't get tiids for collection '{cid}'".format(cid=cid))
abort(404, "couldn't get tiids for this collection...maybe doesn't exist?")
# put each of them on the update queue
for tiid in tiids:
logger.debug("In update_item with tiid " + tiid)
# set this so we know when it's still updating later on
myredis.set_num_providers_left(tiid, ProviderFactory.num_providers_with_metrics(default_settings.PROVIDERS))
item_doc = mydao.get(tiid)
try:
myredis.add_to_alias_queue(item_doc["_id"], item_doc["aliases"])
except (KeyError, TypeError):
logger.debug("couldn't get item_doc for {tiid}. Skipping its update".format(tiid=tiid))
pass
resp = make_response("true", 200)
resp.mimetype = "application/json"
return resp
示例2: prep_collection_items
# 需要导入模块: from totalimpact.providers.provider import ProviderFactory [as 别名]
# 或者: from totalimpact.providers.provider.ProviderFactory import num_providers_with_metrics [as 别名]
def prep_collection_items(aliases):
logger.info("got a list of aliases; creating new items for them.")
try:
# remove unprintable characters and change list to tuples
clean_aliases = [(clean_id(namespace), clean_id(nid)) for [namespace, nid] in aliases]
except ValueError:
logger.error(
"bad input to POST /collection (requires [namespace, id] pairs):{input}".format(input=str(clean_aliases))
)
abort(404, "POST /collection requires a list of [namespace, id] pairs.")
logger.debug(
"POST /collection got list of aliases; creating new items for {aliases}".format(aliases=str(clean_aliases))
)
(tiids, items) = create_or_find_items_from_aliases(clean_aliases)
logger.debug("POST /collection saving a group of {num} new items: {items}".format(num=len(items), items=str(items)))
# batch upload the new docs to the db
# make sure they are there before the provider updates start happening
for doc in mydao.db.update(items):
pass
# for each item, set the number of providers that need to run before the update is done
# and put them on the update queue
for item in items:
myredis.set_num_providers_left(
item["_id"], ProviderFactory.num_providers_with_metrics(default_settings.PROVIDERS)
)
myredis.add_to_alias_queue(item["_id"], item["aliases"])
return tiids
示例3: create_item
# 需要导入模块: from totalimpact.providers.provider import ProviderFactory [as 别名]
# 或者: from totalimpact.providers.provider.ProviderFactory import num_providers_with_metrics [as 别名]
def create_item(namespace, nid, myredis, mydao):
logger.debug("In create_item with alias" + str((namespace, nid)))
item = make()
namespace = clean_id(namespace)
nid = clean_id(nid)
item["aliases"][namespace] = [nid]
item["aliases"] = canonical_aliases(item["aliases"])
# set this so we know when it's still updating later on
myredis.set_num_providers_left(
item["_id"],
ProviderFactory.num_providers_with_metrics(default_settings.PROVIDERS)
)
mydao.save(item)
myredis.add_to_alias_queue(item["_id"], item["aliases"])
logger.info("Created new item '{id}' with alias '{alias}'".format(
id=item["_id"],
alias=str((namespace, nid))
))
mixpanel.track("Create:Item", {"Namespace":namespace})
try:
return item["_id"]
except AttributeError:
abort(500)
示例4: create_item
# 需要导入模块: from totalimpact.providers.provider import ProviderFactory [as 别名]
# 或者: from totalimpact.providers.provider.ProviderFactory import num_providers_with_metrics [as 别名]
def create_item(namespace, nid):
logger.debug("In create_item with alias" + str((namespace, nid)))
item = ItemFactory.make()
# set this so we know when it's still updating later on
myredis.set_num_providers_left(item["_id"], ProviderFactory.num_providers_with_metrics(default_settings.PROVIDERS))
item["aliases"][namespace] = [nid]
mydao.save(item)
myredis.add_to_alias_queue(item["_id"], item["aliases"])
logger.info("Created new item '{id}' with alias '{alias}'".format(id=item["_id"], alias=str((namespace, nid))))
try:
return item["_id"]
except AttributeError:
abort(500)
示例5: start_item_update
# 需要导入模块: from totalimpact.providers.provider import ProviderFactory [as 别名]
# 或者: from totalimpact.providers.provider.ProviderFactory import num_providers_with_metrics [as 别名]
def start_item_update(tiids, myredis, mydao, sleep_in_seconds=0):
# put each of them on the update queue
for tiid in tiids:
logger.debug("In start_item_update with tiid " + tiid)
# set this so we know when it's still updating later on
myredis.set_num_providers_left(
tiid,
ProviderFactory.num_providers_with_metrics(default_settings.PROVIDERS)
)
item_doc = mydao.get(tiid)
try:
myredis.add_to_alias_queue(item_doc["_id"], item_doc["aliases"])
except (KeyError, TypeError):
logger.debug("couldn't get item_doc for {tiid}. Skipping its update".format(
tiid=tiid))
pass
time.sleep(sleep_in_seconds)
示例6: start_item_update
# 需要导入模块: from totalimpact.providers.provider import ProviderFactory [as 别名]
# 或者: from totalimpact.providers.provider.ProviderFactory import num_providers_with_metrics [as 别名]
def start_item_update(tiid, aliases_dict, myredis):
logger.debug(u"In start_item_update with {tiid}, /biblio_print {aliases_dict}".format(
tiid=tiid, aliases_dict=aliases_dict))
myredis.set_num_providers_left(tiid,
ProviderFactory.num_providers_with_metrics(default_settings.PROVIDERS))
myredis.add_to_alias_queue(tiid, aliases_dict)