id
int32
0
252k
repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
75
19.8k
code_tokens
list
docstring
stringlengths
3
17.3k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
87
242
220,600
pmorissette/bt
bt/core.py
StrategyBase.update
def update(self, date, data=None, inow=None): """ Update strategy. Updates prices, values, weight, etc. """ # resolve stale state self.root.stale = False # update helpers on date change # also set newpt flag newpt = False if self.now == 0: ...
python
def update(self, date, data=None, inow=None): """ Update strategy. Updates prices, values, weight, etc. """ # resolve stale state self.root.stale = False # update helpers on date change # also set newpt flag newpt = False if self.now == 0: ...
[ "def", "update", "(", "self", ",", "date", ",", "data", "=", "None", ",", "inow", "=", "None", ")", ":", "# resolve stale state", "self", ".", "root", ".", "stale", "=", "False", "# update helpers on date change", "# also set newpt flag", "newpt", "=", "False"...
Update strategy. Updates prices, values, weight, etc.
[ "Update", "strategy", ".", "Updates", "prices", "values", "weight", "etc", "." ]
0363e6fa100d9392dd18e32e3d8379d5e83c28fa
https://github.com/pmorissette/bt/blob/0363e6fa100d9392dd18e32e3d8379d5e83c28fa/bt/core.py#L484-L586
220,601
pmorissette/bt
bt/core.py
StrategyBase.adjust
def adjust(self, amount, update=True, flow=True, fee=0.0): """ Adjust capital - used to inject capital to a Strategy. This injection of capital will have no effect on the children. Args: * amount (float): Amount to adjust by. * update (bool): Force update? ...
python
def adjust(self, amount, update=True, flow=True, fee=0.0): """ Adjust capital - used to inject capital to a Strategy. This injection of capital will have no effect on the children. Args: * amount (float): Amount to adjust by. * update (bool): Force update? ...
[ "def", "adjust", "(", "self", ",", "amount", ",", "update", "=", "True", ",", "flow", "=", "True", ",", "fee", "=", "0.0", ")", ":", "# adjust capital", "self", ".", "_capital", "+=", "amount", "self", ".", "_last_fee", "+=", "fee", "# if flow - incremen...
Adjust capital - used to inject capital to a Strategy. This injection of capital will have no effect on the children. Args: * amount (float): Amount to adjust by. * update (bool): Force update? * flow (bool): Is this adjustment a flow? A flow will not have an ...
[ "Adjust", "capital", "-", "used", "to", "inject", "capital", "to", "a", "Strategy", ".", "This", "injection", "of", "capital", "will", "have", "no", "effect", "on", "the", "children", "." ]
0363e6fa100d9392dd18e32e3d8379d5e83c28fa
https://github.com/pmorissette/bt/blob/0363e6fa100d9392dd18e32e3d8379d5e83c28fa/bt/core.py#L589-L618
220,602
pmorissette/bt
bt/core.py
StrategyBase.allocate
def allocate(self, amount, child=None, update=True): """ Allocate capital to Strategy. By default, capital is allocated recursively down the children, proportionally to the children's weights. If a child is specified, capital will be allocated to that specific child. Al...
python
def allocate(self, amount, child=None, update=True): """ Allocate capital to Strategy. By default, capital is allocated recursively down the children, proportionally to the children's weights. If a child is specified, capital will be allocated to that specific child. Al...
[ "def", "allocate", "(", "self", ",", "amount", ",", "child", "=", "None", ",", "update", "=", "True", ")", ":", "# allocate to child", "if", "child", "is", "not", "None", ":", "if", "child", "not", "in", "self", ".", "children", ":", "c", "=", "Secur...
Allocate capital to Strategy. By default, capital is allocated recursively down the children, proportionally to the children's weights. If a child is specified, capital will be allocated to that specific child. Allocation also have a side-effect. They will deduct the same amount ...
[ "Allocate", "capital", "to", "Strategy", ".", "By", "default", "capital", "is", "allocated", "recursively", "down", "the", "children", "proportionally", "to", "the", "children", "s", "weights", ".", "If", "a", "child", "is", "specified", "capital", "will", "be...
0363e6fa100d9392dd18e32e3d8379d5e83c28fa
https://github.com/pmorissette/bt/blob/0363e6fa100d9392dd18e32e3d8379d5e83c28fa/bt/core.py#L621-L673
220,603
pmorissette/bt
bt/core.py
StrategyBase.rebalance
def rebalance(self, weight, child, base=np.nan, update=True): """ Rebalance a child to a given weight. This is a helper method to simplify code logic. This method is used when we want to se the weight of a particular child to a set amount. It is similar to allocate, but it calcu...
python
def rebalance(self, weight, child, base=np.nan, update=True): """ Rebalance a child to a given weight. This is a helper method to simplify code logic. This method is used when we want to se the weight of a particular child to a set amount. It is similar to allocate, but it calcu...
[ "def", "rebalance", "(", "self", ",", "weight", ",", "child", ",", "base", "=", "np", ".", "nan", ",", "update", "=", "True", ")", ":", "# if weight is 0 - we want to close child", "if", "weight", "==", "0", ":", "if", "child", "in", "self", ".", "childr...
Rebalance a child to a given weight. This is a helper method to simplify code logic. This method is used when we want to se the weight of a particular child to a set amount. It is similar to allocate, but it calculates the appropriate allocation based on the current weight. Arg...
[ "Rebalance", "a", "child", "to", "a", "given", "weight", "." ]
0363e6fa100d9392dd18e32e3d8379d5e83c28fa
https://github.com/pmorissette/bt/blob/0363e6fa100d9392dd18e32e3d8379d5e83c28fa/bt/core.py#L676-L722
220,604
pmorissette/bt
bt/core.py
StrategyBase.flatten
def flatten(self): """ Close all child positions. """ # go right to base alloc [c.allocate(-c.value) for c in self._childrenv if c.value != 0]
python
def flatten(self): """ Close all child positions. """ # go right to base alloc [c.allocate(-c.value) for c in self._childrenv if c.value != 0]
[ "def", "flatten", "(", "self", ")", ":", "# go right to base alloc", "[", "c", ".", "allocate", "(", "-", "c", ".", "value", ")", "for", "c", "in", "self", ".", "_childrenv", "if", "c", ".", "value", "!=", "0", "]" ]
Close all child positions.
[ "Close", "all", "child", "positions", "." ]
0363e6fa100d9392dd18e32e3d8379d5e83c28fa
https://github.com/pmorissette/bt/blob/0363e6fa100d9392dd18e32e3d8379d5e83c28fa/bt/core.py#L740-L745
220,605
pmorissette/bt
bt/core.py
SecurityBase.setup
def setup(self, universe): """ Setup Security with universe. Speeds up future runs. Args: * universe (DataFrame): DataFrame of prices with security's name as one of the columns. """ # if we already have all the prices, we will store them to speed up ...
python
def setup(self, universe): """ Setup Security with universe. Speeds up future runs. Args: * universe (DataFrame): DataFrame of prices with security's name as one of the columns. """ # if we already have all the prices, we will store them to speed up ...
[ "def", "setup", "(", "self", ",", "universe", ")", ":", "# if we already have all the prices, we will store them to speed up", "# future updates", "try", ":", "prices", "=", "universe", "[", "self", ".", "name", "]", "except", "KeyError", ":", "prices", "=", "None",...
Setup Security with universe. Speeds up future runs. Args: * universe (DataFrame): DataFrame of prices with security's name as one of the columns.
[ "Setup", "Security", "with", "universe", ".", "Speeds", "up", "future", "runs", "." ]
0363e6fa100d9392dd18e32e3d8379d5e83c28fa
https://github.com/pmorissette/bt/blob/0363e6fa100d9392dd18e32e3d8379d5e83c28fa/bt/core.py#L893-L927
220,606
pmorissette/bt
bt/core.py
SecurityBase.update
def update(self, date, data=None, inow=None): """ Update security with a given date and optionally, some data. This will update price, value, weight, etc. """ # filter for internal calls when position has not changed - nothing to # do. Internal calls (stale root calls) ha...
python
def update(self, date, data=None, inow=None): """ Update security with a given date and optionally, some data. This will update price, value, weight, etc. """ # filter for internal calls when position has not changed - nothing to # do. Internal calls (stale root calls) ha...
[ "def", "update", "(", "self", ",", "date", ",", "data", "=", "None", ",", "inow", "=", "None", ")", ":", "# filter for internal calls when position has not changed - nothing to", "# do. Internal calls (stale root calls) have None data. Also want to", "# make sure date has not cha...
Update security with a given date and optionally, some data. This will update price, value, weight, etc.
[ "Update", "security", "with", "a", "given", "date", "and", "optionally", "some", "data", ".", "This", "will", "update", "price", "value", "weight", "etc", "." ]
0363e6fa100d9392dd18e32e3d8379d5e83c28fa
https://github.com/pmorissette/bt/blob/0363e6fa100d9392dd18e32e3d8379d5e83c28fa/bt/core.py#L930-L983
220,607
pmorissette/bt
bt/core.py
Algo.name
def name(self): """ Algo name. """ if self._name is None: self._name = self.__class__.__name__ return self._name
python
def name(self): """ Algo name. """ if self._name is None: self._name = self.__class__.__name__ return self._name
[ "def", "name", "(", "self", ")", ":", "if", "self", ".", "_name", "is", "None", ":", "self", ".", "_name", "=", "self", ".", "__class__", ".", "__name__", "return", "self", ".", "_name" ]
Algo name.
[ "Algo", "name", "." ]
0363e6fa100d9392dd18e32e3d8379d5e83c28fa
https://github.com/pmorissette/bt/blob/0363e6fa100d9392dd18e32e3d8379d5e83c28fa/bt/core.py#L1217-L1223
220,608
pmorissette/bt
docs/source/_themes/klink/klink/__init__.py
convert_notebooks
def convert_notebooks(): """ Converts IPython Notebooks to proper .rst files and moves static content to the _static directory. """ convert_status = call(['ipython', 'nbconvert', '--to', 'rst', '*.ipynb']) if convert_status != 0: raise SystemError('Conversion failed! Status was %s' % con...
python
def convert_notebooks(): """ Converts IPython Notebooks to proper .rst files and moves static content to the _static directory. """ convert_status = call(['ipython', 'nbconvert', '--to', 'rst', '*.ipynb']) if convert_status != 0: raise SystemError('Conversion failed! Status was %s' % con...
[ "def", "convert_notebooks", "(", ")", ":", "convert_status", "=", "call", "(", "[", "'ipython'", ",", "'nbconvert'", ",", "'--to'", ",", "'rst'", ",", "'*.ipynb'", "]", ")", "if", "convert_status", "!=", "0", ":", "raise", "SystemError", "(", "'Conversion fa...
Converts IPython Notebooks to proper .rst files and moves static content to the _static directory.
[ "Converts", "IPython", "Notebooks", "to", "proper", ".", "rst", "files", "and", "moves", "static", "content", "to", "the", "_static", "directory", "." ]
0363e6fa100d9392dd18e32e3d8379d5e83c28fa
https://github.com/pmorissette/bt/blob/0363e6fa100d9392dd18e32e3d8379d5e83c28fa/docs/source/_themes/klink/klink/__init__.py#L7-L76
220,609
istresearch/scrapy-cluster
utils/scutils/settings_wrapper.py
SettingsWrapper.load
def load(self, local='localsettings.py', default='settings.py'): ''' Load the settings dict @param local: The local settings filename to use @param default: The default settings module to read @return: A dict of the loaded settings ''' self._load_defaults(default...
python
def load(self, local='localsettings.py', default='settings.py'): ''' Load the settings dict @param local: The local settings filename to use @param default: The default settings module to read @return: A dict of the loaded settings ''' self._load_defaults(default...
[ "def", "load", "(", "self", ",", "local", "=", "'localsettings.py'", ",", "default", "=", "'settings.py'", ")", ":", "self", ".", "_load_defaults", "(", "default", ")", "self", ".", "_load_custom", "(", "local", ")", "return", "self", ".", "settings", "(",...
Load the settings dict @param local: The local settings filename to use @param default: The default settings module to read @return: A dict of the loaded settings
[ "Load", "the", "settings", "dict" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/utils/scutils/settings_wrapper.py#L29-L40
220,610
istresearch/scrapy-cluster
utils/scutils/settings_wrapper.py
SettingsWrapper._load_defaults
def _load_defaults(self, default='settings.py'): ''' Load the default settings ''' if default[-3:] == '.py': default = default[:-3] self.my_settings = {} try: settings = importlib.import_module(default) self.my_settings = self._convert...
python
def _load_defaults(self, default='settings.py'): ''' Load the default settings ''' if default[-3:] == '.py': default = default[:-3] self.my_settings = {} try: settings = importlib.import_module(default) self.my_settings = self._convert...
[ "def", "_load_defaults", "(", "self", ",", "default", "=", "'settings.py'", ")", ":", "if", "default", "[", "-", "3", ":", "]", "==", "'.py'", ":", "default", "=", "default", "[", ":", "-", "3", "]", "self", ".", "my_settings", "=", "{", "}", "try"...
Load the default settings
[ "Load", "the", "default", "settings" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/utils/scutils/settings_wrapper.py#L70-L82
220,611
istresearch/scrapy-cluster
utils/scutils/settings_wrapper.py
SettingsWrapper._load_custom
def _load_custom(self, settings_name='localsettings.py'): ''' Load the user defined settings, overriding the defaults ''' if settings_name[-3:] == '.py': settings_name = settings_name[:-3] new_settings = {} try: settings = importlib.import_module...
python
def _load_custom(self, settings_name='localsettings.py'): ''' Load the user defined settings, overriding the defaults ''' if settings_name[-3:] == '.py': settings_name = settings_name[:-3] new_settings = {} try: settings = importlib.import_module...
[ "def", "_load_custom", "(", "self", ",", "settings_name", "=", "'localsettings.py'", ")", ":", "if", "settings_name", "[", "-", "3", ":", "]", "==", "'.py'", ":", "settings_name", "=", "settings_name", "[", ":", "-", "3", "]", "new_settings", "=", "{", "...
Load the user defined settings, overriding the defaults
[ "Load", "the", "user", "defined", "settings", "overriding", "the", "defaults" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/utils/scutils/settings_wrapper.py#L84-L109
220,612
istresearch/scrapy-cluster
utils/scutils/settings_wrapper.py
SettingsWrapper._convert_to_dict
def _convert_to_dict(self, setting): ''' Converts a settings file into a dictionary, ignoring python defaults @param setting: A loaded setting module ''' the_dict = {} set = dir(setting) for key in set: if key in self.ignore: continue ...
python
def _convert_to_dict(self, setting): ''' Converts a settings file into a dictionary, ignoring python defaults @param setting: A loaded setting module ''' the_dict = {} set = dir(setting) for key in set: if key in self.ignore: continue ...
[ "def", "_convert_to_dict", "(", "self", ",", "setting", ")", ":", "the_dict", "=", "{", "}", "set", "=", "dir", "(", "setting", ")", "for", "key", "in", "set", ":", "if", "key", "in", "self", ".", "ignore", ":", "continue", "value", "=", "getattr", ...
Converts a settings file into a dictionary, ignoring python defaults @param setting: A loaded setting module
[ "Converts", "a", "settings", "file", "into", "a", "dictionary", "ignoring", "python", "defaults" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/utils/scutils/settings_wrapper.py#L111-L125
220,613
istresearch/scrapy-cluster
crawler/crawling/distributed_scheduler.py
DistributedScheduler.load_domain_config
def load_domain_config(self, loaded_config): ''' Loads the domain_config and sets up queue_dict @param loaded_config: the yaml loaded config dict from zookeeper ''' self.domain_config = {} # vetting process to ensure correct configs if loaded_config: i...
python
def load_domain_config(self, loaded_config): ''' Loads the domain_config and sets up queue_dict @param loaded_config: the yaml loaded config dict from zookeeper ''' self.domain_config = {} # vetting process to ensure correct configs if loaded_config: i...
[ "def", "load_domain_config", "(", "self", ",", "loaded_config", ")", ":", "self", ".", "domain_config", "=", "{", "}", "# vetting process to ensure correct configs", "if", "loaded_config", ":", "if", "'domains'", "in", "loaded_config", ":", "for", "domain", "in", ...
Loads the domain_config and sets up queue_dict @param loaded_config: the yaml loaded config dict from zookeeper
[ "Loads", "the", "domain_config", "and", "sets", "up", "queue_dict" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/crawler/crawling/distributed_scheduler.py#L130-L149
220,614
istresearch/scrapy-cluster
crawler/crawling/distributed_scheduler.py
DistributedScheduler.update_domain_queues
def update_domain_queues(self): ''' Check to update existing queues already in memory new queues are created elsewhere ''' for key in self.domain_config: final_key = "{name}:{domain}:queue".format( name=self.spider.name, domain=...
python
def update_domain_queues(self): ''' Check to update existing queues already in memory new queues are created elsewhere ''' for key in self.domain_config: final_key = "{name}:{domain}:queue".format( name=self.spider.name, domain=...
[ "def", "update_domain_queues", "(", "self", ")", ":", "for", "key", "in", "self", ".", "domain_config", ":", "final_key", "=", "\"{name}:{domain}:queue\"", ".", "format", "(", "name", "=", "self", ".", "spider", ".", "name", ",", "domain", "=", "key", ")",...
Check to update existing queues already in memory new queues are created elsewhere
[ "Check", "to", "update", "existing", "queues", "already", "in", "memory", "new", "queues", "are", "created", "elsewhere" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/crawler/crawling/distributed_scheduler.py#L151-L172
220,615
istresearch/scrapy-cluster
crawler/crawling/distributed_scheduler.py
DistributedScheduler.create_queues
def create_queues(self): ''' Updates the in memory list of the redis queues Creates new throttled queue instances if it does not have them ''' # new config could have loaded between scrapes newConf = self.check_config() self.queue_keys = self.redis_conn.keys(self...
python
def create_queues(self): ''' Updates the in memory list of the redis queues Creates new throttled queue instances if it does not have them ''' # new config could have loaded between scrapes newConf = self.check_config() self.queue_keys = self.redis_conn.keys(self...
[ "def", "create_queues", "(", "self", ")", ":", "# new config could have loaded between scrapes", "newConf", "=", "self", ".", "check_config", "(", ")", "self", ".", "queue_keys", "=", "self", ".", "redis_conn", ".", "keys", "(", "self", ".", "spider", ".", "na...
Updates the in memory list of the redis queues Creates new throttled queue instances if it does not have them
[ "Updates", "the", "in", "memory", "list", "of", "the", "redis", "queues", "Creates", "new", "throttled", "queue", "instances", "if", "it", "does", "not", "have", "them" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/crawler/crawling/distributed_scheduler.py#L202-L248
220,616
istresearch/scrapy-cluster
crawler/crawling/distributed_scheduler.py
DistributedScheduler.expire_queues
def expire_queues(self): ''' Expires old queue_dict keys that have not been used in a long time. Prevents slow memory build up when crawling lots of different domains ''' curr_time = time.time() for key in list(self.queue_dict): diff = curr_time - self.queue_d...
python
def expire_queues(self): ''' Expires old queue_dict keys that have not been used in a long time. Prevents slow memory build up when crawling lots of different domains ''' curr_time = time.time() for key in list(self.queue_dict): diff = curr_time - self.queue_d...
[ "def", "expire_queues", "(", "self", ")", ":", "curr_time", "=", "time", ".", "time", "(", ")", "for", "key", "in", "list", "(", "self", ".", "queue_dict", ")", ":", "diff", "=", "curr_time", "-", "self", ".", "queue_dict", "[", "key", "]", "[", "1...
Expires old queue_dict keys that have not been used in a long time. Prevents slow memory build up when crawling lots of different domains
[ "Expires", "old", "queue_dict", "keys", "that", "have", "not", "been", "used", "in", "a", "long", "time", ".", "Prevents", "slow", "memory", "build", "up", "when", "crawling", "lots", "of", "different", "domains" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/crawler/crawling/distributed_scheduler.py#L250-L262
220,617
istresearch/scrapy-cluster
crawler/crawling/distributed_scheduler.py
DistributedScheduler.update_ipaddress
def update_ipaddress(self): ''' Updates the scheduler so it knows its own ip address ''' # assign local ip in case of exception self.old_ip = self.my_ip self.my_ip = '127.0.0.1' try: obj = urllib.request.urlopen(settings.get('PUBLIC_IP_URL', ...
python
def update_ipaddress(self): ''' Updates the scheduler so it knows its own ip address ''' # assign local ip in case of exception self.old_ip = self.my_ip self.my_ip = '127.0.0.1' try: obj = urllib.request.urlopen(settings.get('PUBLIC_IP_URL', ...
[ "def", "update_ipaddress", "(", "self", ")", ":", "# assign local ip in case of exception", "self", ".", "old_ip", "=", "self", ".", "my_ip", "self", ".", "my_ip", "=", "'127.0.0.1'", "try", ":", "obj", "=", "urllib", ".", "request", ".", "urlopen", "(", "se...
Updates the scheduler so it knows its own ip address
[ "Updates", "the", "scheduler", "so", "it", "knows", "its", "own", "ip", "address" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/crawler/crawling/distributed_scheduler.py#L275-L298
220,618
istresearch/scrapy-cluster
crawler/crawling/distributed_scheduler.py
DistributedScheduler.is_blacklisted
def is_blacklisted(self, appid, crawlid): ''' Checks the redis blacklist for crawls that should not be propagated either from expiring or stopped @return: True if the appid crawlid combo is blacklisted ''' key_check = '{appid}||{crawlid}'.format(appid=appid, ...
python
def is_blacklisted(self, appid, crawlid): ''' Checks the redis blacklist for crawls that should not be propagated either from expiring or stopped @return: True if the appid crawlid combo is blacklisted ''' key_check = '{appid}||{crawlid}'.format(appid=appid, ...
[ "def", "is_blacklisted", "(", "self", ",", "appid", ",", "crawlid", ")", ":", "key_check", "=", "'{appid}||{crawlid}'", ".", "format", "(", "appid", "=", "appid", ",", "crawlid", "=", "crawlid", ")", "redis_key", "=", "self", ".", "spider", ".", "name", ...
Checks the redis blacklist for crawls that should not be propagated either from expiring or stopped @return: True if the appid crawlid combo is blacklisted
[ "Checks", "the", "redis", "blacklist", "for", "crawls", "that", "should", "not", "be", "propagated", "either", "from", "expiring", "or", "stopped" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/crawler/crawling/distributed_scheduler.py#L375-L384
220,619
istresearch/scrapy-cluster
crawler/crawling/distributed_scheduler.py
DistributedScheduler.enqueue_request
def enqueue_request(self, request): ''' Pushes a request from the spider into the proper throttled queue ''' if not request.dont_filter and self.dupefilter.request_seen(request): self.logger.debug("Request not added back to redis") return req_dict = self.r...
python
def enqueue_request(self, request): ''' Pushes a request from the spider into the proper throttled queue ''' if not request.dont_filter and self.dupefilter.request_seen(request): self.logger.debug("Request not added back to redis") return req_dict = self.r...
[ "def", "enqueue_request", "(", "self", ",", "request", ")", ":", "if", "not", "request", ".", "dont_filter", "and", "self", ".", "dupefilter", ".", "request_seen", "(", "request", ")", ":", "self", ".", "logger", ".", "debug", "(", "\"Request not added back ...
Pushes a request from the spider into the proper throttled queue
[ "Pushes", "a", "request", "from", "the", "spider", "into", "the", "proper", "throttled", "queue" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/crawler/crawling/distributed_scheduler.py#L386-L436
220,620
istresearch/scrapy-cluster
crawler/crawling/distributed_scheduler.py
DistributedScheduler.request_to_dict
def request_to_dict(self, request): ''' Convert Request object to a dict. modified from scrapy.utils.reqser ''' req_dict = { # urls should be safe (safe_string_url) 'url': to_unicode(request.url), 'method': request.method, 'headers'...
python
def request_to_dict(self, request): ''' Convert Request object to a dict. modified from scrapy.utils.reqser ''' req_dict = { # urls should be safe (safe_string_url) 'url': to_unicode(request.url), 'method': request.method, 'headers'...
[ "def", "request_to_dict", "(", "self", ",", "request", ")", ":", "req_dict", "=", "{", "# urls should be safe (safe_string_url)", "'url'", ":", "to_unicode", "(", "request", ".", "url", ")", ",", "'method'", ":", "request", ".", "method", ",", "'headers'", ":"...
Convert Request object to a dict. modified from scrapy.utils.reqser
[ "Convert", "Request", "object", "to", "a", "dict", ".", "modified", "from", "scrapy", ".", "utils", ".", "reqser" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/crawler/crawling/distributed_scheduler.py#L438-L458
220,621
istresearch/scrapy-cluster
crawler/crawling/distributed_scheduler.py
DistributedScheduler.find_item
def find_item(self): ''' Finds an item from the throttled queues ''' random.shuffle(self.queue_keys) count = 0 while count <= self.item_retries: for key in self.queue_keys: # skip if the whole domain has been blacklisted in zookeeper ...
python
def find_item(self): ''' Finds an item from the throttled queues ''' random.shuffle(self.queue_keys) count = 0 while count <= self.item_retries: for key in self.queue_keys: # skip if the whole domain has been blacklisted in zookeeper ...
[ "def", "find_item", "(", "self", ")", ":", "random", ".", "shuffle", "(", "self", ".", "queue_keys", ")", "count", "=", "0", "while", "count", "<=", "self", ".", "item_retries", ":", "for", "key", "in", "self", ".", "queue_keys", ":", "# skip if the whol...
Finds an item from the throttled queues
[ "Finds", "an", "item", "from", "the", "throttled", "queues" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/crawler/crawling/distributed_scheduler.py#L460-L482
220,622
istresearch/scrapy-cluster
crawler/crawling/distributed_scheduler.py
DistributedScheduler.next_request
def next_request(self): ''' Logic to handle getting a new url request, from a bunch of different queues ''' t = time.time() # update the redis queues every so often if t - self.update_time > self.update_interval: self.update_time = t self.c...
python
def next_request(self): ''' Logic to handle getting a new url request, from a bunch of different queues ''' t = time.time() # update the redis queues every so often if t - self.update_time > self.update_interval: self.update_time = t self.c...
[ "def", "next_request", "(", "self", ")", ":", "t", "=", "time", ".", "time", "(", ")", "# update the redis queues every so often", "if", "t", "-", "self", ".", "update_time", ">", "self", ".", "update_interval", ":", "self", ".", "update_time", "=", "t", "...
Logic to handle getting a new url request, from a bunch of different queues
[ "Logic", "to", "handle", "getting", "a", "new", "url", "request", "from", "a", "bunch", "of", "different", "queues" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/crawler/crawling/distributed_scheduler.py#L484-L548
220,623
istresearch/scrapy-cluster
crawler/crawling/distributed_scheduler.py
DistributedScheduler.parse_cookie
def parse_cookie(self, string): ''' Parses a cookie string like returned in a Set-Cookie header @param string: The cookie string @return: the cookie dict ''' results = re.findall('([^=]+)=([^\;]+);?\s?', string) my_dict = {} for item in results: ...
python
def parse_cookie(self, string): ''' Parses a cookie string like returned in a Set-Cookie header @param string: The cookie string @return: the cookie dict ''' results = re.findall('([^=]+)=([^\;]+);?\s?', string) my_dict = {} for item in results: ...
[ "def", "parse_cookie", "(", "self", ",", "string", ")", ":", "results", "=", "re", ".", "findall", "(", "'([^=]+)=([^\\;]+);?\\s?'", ",", "string", ")", "my_dict", "=", "{", "}", "for", "item", "in", "results", ":", "my_dict", "[", "item", "[", "0", "]...
Parses a cookie string like returned in a Set-Cookie header @param string: The cookie string @return: the cookie dict
[ "Parses", "a", "cookie", "string", "like", "returned", "in", "a", "Set", "-", "Cookie", "header" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/crawler/crawling/distributed_scheduler.py#L550-L561
220,624
istresearch/scrapy-cluster
crawler/crawling/pipelines.py
KafkaPipeline._clean_item
def _clean_item(self, item): ''' Cleans the item to be logged ''' item_copy = dict(item) del item_copy['body'] del item_copy['links'] del item_copy['response_headers'] del item_copy['request_headers'] del item_copy['status_code'] del item_c...
python
def _clean_item(self, item): ''' Cleans the item to be logged ''' item_copy = dict(item) del item_copy['body'] del item_copy['links'] del item_copy['response_headers'] del item_copy['request_headers'] del item_copy['status_code'] del item_c...
[ "def", "_clean_item", "(", "self", ",", "item", ")", ":", "item_copy", "=", "dict", "(", "item", ")", "del", "item_copy", "[", "'body'", "]", "del", "item_copy", "[", "'links'", "]", "del", "item_copy", "[", "'response_headers'", "]", "del", "item_copy", ...
Cleans the item to be logged
[ "Cleans", "the", "item", "to", "be", "logged" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/crawler/crawling/pipelines.py#L138-L153
220,625
istresearch/scrapy-cluster
crawler/crawling/pipelines.py
KafkaPipeline._kafka_success
def _kafka_success(self, item, spider, response): ''' Callback for successful send ''' item['success'] = True item = self._clean_item(item) item['spiderid'] = spider.name self.logger.info("Sent page to Kafka", item)
python
def _kafka_success(self, item, spider, response): ''' Callback for successful send ''' item['success'] = True item = self._clean_item(item) item['spiderid'] = spider.name self.logger.info("Sent page to Kafka", item)
[ "def", "_kafka_success", "(", "self", ",", "item", ",", "spider", ",", "response", ")", ":", "item", "[", "'success'", "]", "=", "True", "item", "=", "self", ".", "_clean_item", "(", "item", ")", "item", "[", "'spiderid'", "]", "=", "spider", ".", "n...
Callback for successful send
[ "Callback", "for", "successful", "send" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/crawler/crawling/pipelines.py#L155-L162
220,626
istresearch/scrapy-cluster
crawler/crawling/pipelines.py
KafkaPipeline._kafka_failure
def _kafka_failure(self, item, spider, response): ''' Callback for failed send ''' item['success'] = False item['exception'] = traceback.format_exc() item['spiderid'] = spider.name item = self._clean_item(item) self.logger.error("Failed to send page to Kaf...
python
def _kafka_failure(self, item, spider, response): ''' Callback for failed send ''' item['success'] = False item['exception'] = traceback.format_exc() item['spiderid'] = spider.name item = self._clean_item(item) self.logger.error("Failed to send page to Kaf...
[ "def", "_kafka_failure", "(", "self", ",", "item", ",", "spider", ",", "response", ")", ":", "item", "[", "'success'", "]", "=", "False", "item", "[", "'exception'", "]", "=", "traceback", ".", "format_exc", "(", ")", "item", "[", "'spiderid'", "]", "=...
Callback for failed send
[ "Callback", "for", "failed", "send" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/crawler/crawling/pipelines.py#L165-L173
220,627
istresearch/scrapy-cluster
crawler/crawling/spiders/redis_spider.py
RedisSpider.reconstruct_headers
def reconstruct_headers(self, response): """ Purpose of this method is to reconstruct the headers dictionary that is normally passed in with a "response" object from scrapy. Args: response: A scrapy response object Returns: A dictionary that mirrors the "response.he...
python
def reconstruct_headers(self, response): """ Purpose of this method is to reconstruct the headers dictionary that is normally passed in with a "response" object from scrapy. Args: response: A scrapy response object Returns: A dictionary that mirrors the "response.he...
[ "def", "reconstruct_headers", "(", "self", ",", "response", ")", ":", "header_dict", "=", "{", "}", "# begin reconstructing headers from scratch...", "for", "key", "in", "list", "(", "response", ".", "headers", ".", "keys", "(", ")", ")", ":", "key_item_list", ...
Purpose of this method is to reconstruct the headers dictionary that is normally passed in with a "response" object from scrapy. Args: response: A scrapy response object Returns: A dictionary that mirrors the "response.headers" dictionary that is normally within a response ...
[ "Purpose", "of", "this", "method", "is", "to", "reconstruct", "the", "headers", "dictionary", "that", "is", "normally", "passed", "in", "with", "a", "response", "object", "from", "scrapy", "." ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/crawler/crawling/spiders/redis_spider.py#L36-L61
220,628
istresearch/scrapy-cluster
kafka-monitor/plugins/scraper_handler.py
ScraperHandler.handle
def handle(self, dict): ''' Processes a vaild crawl request @param dict: a valid dictionary object ''' # format key ex_res = self.extract(dict['url']) key = "{sid}:{dom}.{suf}:queue".format( sid=dict['spiderid'], dom=ex_res.domain, ...
python
def handle(self, dict): ''' Processes a vaild crawl request @param dict: a valid dictionary object ''' # format key ex_res = self.extract(dict['url']) key = "{sid}:{dom}.{suf}:queue".format( sid=dict['spiderid'], dom=ex_res.domain, ...
[ "def", "handle", "(", "self", ",", "dict", ")", ":", "# format key", "ex_res", "=", "self", ".", "extract", "(", "dict", "[", "'url'", "]", ")", "key", "=", "\"{sid}:{dom}.{suf}:queue\"", ".", "format", "(", "sid", "=", "dict", "[", "'spiderid'", "]", ...
Processes a vaild crawl request @param dict: a valid dictionary object
[ "Processes", "a", "vaild", "crawl", "request" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/kafka-monitor/plugins/scraper_handler.py#L31-L60
220,629
istresearch/scrapy-cluster
utils/scutils/method_timer.py
MethodTimer.timeout
def timeout(timeout_time, default): ''' Decorate a method so it is required to execute in a given time period, or return a default value. ''' def timeout_function(f): def f2(*args): def timeout_handler(signum, frame): raise MethodTi...
python
def timeout(timeout_time, default): ''' Decorate a method so it is required to execute in a given time period, or return a default value. ''' def timeout_function(f): def f2(*args): def timeout_handler(signum, frame): raise MethodTi...
[ "def", "timeout", "(", "timeout_time", ",", "default", ")", ":", "def", "timeout_function", "(", "f", ")", ":", "def", "f2", "(", "*", "args", ")", ":", "def", "timeout_handler", "(", "signum", ",", "frame", ")", ":", "raise", "MethodTimer", ".", "Deco...
Decorate a method so it is required to execute in a given time period, or return a default value.
[ "Decorate", "a", "method", "so", "it", "is", "required", "to", "execute", "in", "a", "given", "time", "period", "or", "return", "a", "default", "value", "." ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/utils/scutils/method_timer.py#L33-L55
220,630
istresearch/scrapy-cluster
crawler/crawling/redis_stats_middleware.py
RedisStatsMiddleware._setup_stats_status_codes
def _setup_stats_status_codes(self, spider_name): ''' Sets up the status code stats collectors ''' self.stats_dict[spider_name] = { 'status_codes': {} } self.stats_dict[spider_name]['status_codes'] = {} hostname = self._get_hostname() # we chos...
python
def _setup_stats_status_codes(self, spider_name): ''' Sets up the status code stats collectors ''' self.stats_dict[spider_name] = { 'status_codes': {} } self.stats_dict[spider_name]['status_codes'] = {} hostname = self._get_hostname() # we chos...
[ "def", "_setup_stats_status_codes", "(", "self", ",", "spider_name", ")", ":", "self", ".", "stats_dict", "[", "spider_name", "]", "=", "{", "'status_codes'", ":", "{", "}", "}", "self", ".", "stats_dict", "[", "spider_name", "]", "[", "'status_codes'", "]",...
Sets up the status code stats collectors
[ "Sets", "up", "the", "status", "code", "stats", "collectors" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/crawler/crawling/redis_stats_middleware.py#L66-L104
220,631
istresearch/scrapy-cluster
redis-monitor/plugins/kafka_base_monitor.py
KafkaBaseMonitor.setup
def setup(self, settings): ''' Setup the handler @param settings: The loaded settings file ''' self.producer = self._create_producer(settings) self.topic_prefix = settings['KAFKA_TOPIC_PREFIX'] self.use_appid_topics = settings['KAFKA_APPID_TOPICS'] self...
python
def setup(self, settings): ''' Setup the handler @param settings: The loaded settings file ''' self.producer = self._create_producer(settings) self.topic_prefix = settings['KAFKA_TOPIC_PREFIX'] self.use_appid_topics = settings['KAFKA_APPID_TOPICS'] self...
[ "def", "setup", "(", "self", ",", "settings", ")", ":", "self", ".", "producer", "=", "self", ".", "_create_producer", "(", "settings", ")", "self", ".", "topic_prefix", "=", "settings", "[", "'KAFKA_TOPIC_PREFIX'", "]", "self", ".", "use_appid_topics", "=",...
Setup the handler @param settings: The loaded settings file
[ "Setup", "the", "handler" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/redis-monitor/plugins/kafka_base_monitor.py#L19-L31
220,632
istresearch/scrapy-cluster
redis-monitor/plugins/kafka_base_monitor.py
KafkaBaseMonitor._send_to_kafka
def _send_to_kafka(self, master): ''' Sends the message back to Kafka @param master: the final dict to send @returns: True if successfully sent to kafka ''' appid_topic = "{prefix}.outbound_{appid}".format( prefix=self.t...
python
def _send_to_kafka(self, master): ''' Sends the message back to Kafka @param master: the final dict to send @returns: True if successfully sent to kafka ''' appid_topic = "{prefix}.outbound_{appid}".format( prefix=self.t...
[ "def", "_send_to_kafka", "(", "self", ",", "master", ")", ":", "appid_topic", "=", "\"{prefix}.outbound_{appid}\"", ".", "format", "(", "prefix", "=", "self", ".", "topic_prefix", ",", "appid", "=", "master", "[", "'appid'", "]", ")", "firehose_topic", "=", ...
Sends the message back to Kafka @param master: the final dict to send @returns: True if successfully sent to kafka
[ "Sends", "the", "message", "back", "to", "Kafka" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/redis-monitor/plugins/kafka_base_monitor.py#L66-L94
220,633
istresearch/scrapy-cluster
kafka-monitor/kafka_monitor.py
KafkaMonitor._load_plugins
def _load_plugins(self): ''' Sets up all plugins, defaults and settings.py ''' plugins = self.settings['PLUGINS'] self.plugins_dict = {} for key in plugins: # skip loading the plugin if its value is None if plugins[key] is None: co...
python
def _load_plugins(self): ''' Sets up all plugins, defaults and settings.py ''' plugins = self.settings['PLUGINS'] self.plugins_dict = {} for key in plugins: # skip loading the plugin if its value is None if plugins[key] is None: co...
[ "def", "_load_plugins", "(", "self", ")", ":", "plugins", "=", "self", ".", "settings", "[", "'PLUGINS'", "]", "self", ".", "plugins_dict", "=", "{", "}", "for", "key", "in", "plugins", ":", "# skip loading the plugin if its value is None", "if", "plugins", "[...
Sets up all plugins, defaults and settings.py
[ "Sets", "up", "all", "plugins", "defaults", "and", "settings", ".", "py" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/kafka-monitor/kafka_monitor.py#L62-L91
220,634
istresearch/scrapy-cluster
kafka-monitor/kafka_monitor.py
KafkaMonitor._setup_stats
def _setup_stats(self): ''' Sets up the stats collection ''' self.stats_dict = {} redis_conn = redis.Redis(host=self.settings['REDIS_HOST'], port=self.settings['REDIS_PORT'], db=self.settings.get('REDIS_DB')) ...
python
def _setup_stats(self): ''' Sets up the stats collection ''' self.stats_dict = {} redis_conn = redis.Redis(host=self.settings['REDIS_HOST'], port=self.settings['REDIS_PORT'], db=self.settings.get('REDIS_DB')) ...
[ "def", "_setup_stats", "(", "self", ")", ":", "self", ".", "stats_dict", "=", "{", "}", "redis_conn", "=", "redis", ".", "Redis", "(", "host", "=", "self", ".", "settings", "[", "'REDIS_HOST'", "]", ",", "port", "=", "self", ".", "settings", "[", "'R...
Sets up the stats collection
[ "Sets", "up", "the", "stats", "collection" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/kafka-monitor/kafka_monitor.py#L118-L141
220,635
istresearch/scrapy-cluster
kafka-monitor/kafka_monitor.py
KafkaMonitor._setup_stats_total
def _setup_stats_total(self, redis_conn): ''' Sets up the total stats collectors @param redis_conn: the redis connection ''' self.stats_dict['total'] = {} self.stats_dict['fail'] = {} temp_key1 = 'stats:kafka-monitor:total' temp_key2 = 'stats:kafka-monito...
python
def _setup_stats_total(self, redis_conn): ''' Sets up the total stats collectors @param redis_conn: the redis connection ''' self.stats_dict['total'] = {} self.stats_dict['fail'] = {} temp_key1 = 'stats:kafka-monitor:total' temp_key2 = 'stats:kafka-monito...
[ "def", "_setup_stats_total", "(", "self", ",", "redis_conn", ")", ":", "self", ".", "stats_dict", "[", "'total'", "]", "=", "{", "}", "self", ".", "stats_dict", "[", "'fail'", "]", "=", "{", "}", "temp_key1", "=", "'stats:kafka-monitor:total'", "temp_key2", ...
Sets up the total stats collectors @param redis_conn: the redis connection
[ "Sets", "up", "the", "total", "stats", "collectors" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/kafka-monitor/kafka_monitor.py#L143-L183
220,636
istresearch/scrapy-cluster
kafka-monitor/kafka_monitor.py
KafkaMonitor._main_loop
def _main_loop(self): ''' Continuous loop that reads from a kafka topic and tries to validate incoming messages ''' self.logger.debug("Processing messages") old_time = 0 while True: self._process_messages() if self.settings['STATS_DUMP'] !=...
python
def _main_loop(self): ''' Continuous loop that reads from a kafka topic and tries to validate incoming messages ''' self.logger.debug("Processing messages") old_time = 0 while True: self._process_messages() if self.settings['STATS_DUMP'] !=...
[ "def", "_main_loop", "(", "self", ")", ":", "self", ".", "logger", ".", "debug", "(", "\"Processing messages\"", ")", "old_time", "=", "0", "while", "True", ":", "self", ".", "_process_messages", "(", ")", "if", "self", ".", "settings", "[", "'STATS_DUMP'"...
Continuous loop that reads from a kafka topic and tries to validate incoming messages
[ "Continuous", "loop", "that", "reads", "from", "a", "kafka", "topic", "and", "tries", "to", "validate", "incoming", "messages" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/kafka-monitor/kafka_monitor.py#L247-L264
220,637
istresearch/scrapy-cluster
kafka-monitor/kafka_monitor.py
KafkaMonitor._dump_stats
def _dump_stats(self): ''' Dumps the stats out ''' extras = {} if 'total' in self.stats_dict: self.logger.debug("Compiling total/fail dump stats") for key in self.stats_dict['total']: final = 'total_{t}'.format(t=key) extras...
python
def _dump_stats(self): ''' Dumps the stats out ''' extras = {} if 'total' in self.stats_dict: self.logger.debug("Compiling total/fail dump stats") for key in self.stats_dict['total']: final = 'total_{t}'.format(t=key) extras...
[ "def", "_dump_stats", "(", "self", ")", ":", "extras", "=", "{", "}", "if", "'total'", "in", "self", ".", "stats_dict", ":", "self", ".", "logger", ".", "debug", "(", "\"Compiling total/fail dump stats\"", ")", "for", "key", "in", "self", ".", "stats_dict"...
Dumps the stats out
[ "Dumps", "the", "stats", "out" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/kafka-monitor/kafka_monitor.py#L367-L392
220,638
istresearch/scrapy-cluster
kafka-monitor/kafka_monitor.py
KafkaMonitor.run
def run(self): ''' Set up and run ''' self._setup_kafka() self._load_plugins() self._setup_stats() self._main_loop()
python
def run(self): ''' Set up and run ''' self._setup_kafka() self._load_plugins() self._setup_stats() self._main_loop()
[ "def", "run", "(", "self", ")", ":", "self", ".", "_setup_kafka", "(", ")", "self", ".", "_load_plugins", "(", ")", "self", ".", "_setup_stats", "(", ")", "self", ".", "_main_loop", "(", ")" ]
Set up and run
[ "Set", "up", "and", "run" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/kafka-monitor/kafka_monitor.py#L394-L401
220,639
istresearch/scrapy-cluster
kafka-monitor/kafka_monitor.py
KafkaMonitor._report_self
def _report_self(self): ''' Reports the kafka monitor uuid to redis ''' key = "stats:kafka-monitor:self:{m}:{u}".format( m=socket.gethostname(), u=self.my_uuid) self.redis_conn.set(key, time.time()) self.redis_conn.expire(key, self.settings['HEARTB...
python
def _report_self(self): ''' Reports the kafka monitor uuid to redis ''' key = "stats:kafka-monitor:self:{m}:{u}".format( m=socket.gethostname(), u=self.my_uuid) self.redis_conn.set(key, time.time()) self.redis_conn.expire(key, self.settings['HEARTB...
[ "def", "_report_self", "(", "self", ")", ":", "key", "=", "\"stats:kafka-monitor:self:{m}:{u}\"", ".", "format", "(", "m", "=", "socket", ".", "gethostname", "(", ")", ",", "u", "=", "self", ".", "my_uuid", ")", "self", ".", "redis_conn", ".", "set", "("...
Reports the kafka monitor uuid to redis
[ "Reports", "the", "kafka", "monitor", "uuid", "to", "redis" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/kafka-monitor/kafka_monitor.py#L403-L411
220,640
istresearch/scrapy-cluster
kafka-monitor/kafka_monitor.py
KafkaMonitor.feed
def feed(self, json_item): ''' Feeds a json item into the Kafka topic @param json_item: The loaded json object ''' @MethodTimer.timeout(self.settings['KAFKA_FEED_TIMEOUT'], False) def _feed(json_item): producer = self._create_producer() topic = se...
python
def feed(self, json_item): ''' Feeds a json item into the Kafka topic @param json_item: The loaded json object ''' @MethodTimer.timeout(self.settings['KAFKA_FEED_TIMEOUT'], False) def _feed(json_item): producer = self._create_producer() topic = se...
[ "def", "feed", "(", "self", ",", "json_item", ")", ":", "@", "MethodTimer", ".", "timeout", "(", "self", ".", "settings", "[", "'KAFKA_FEED_TIMEOUT'", "]", ",", "False", ")", "def", "_feed", "(", "json_item", ")", ":", "producer", "=", "self", ".", "_c...
Feeds a json item into the Kafka topic @param json_item: The loaded json object
[ "Feeds", "a", "json", "item", "into", "the", "Kafka", "topic" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/kafka-monitor/kafka_monitor.py#L413-L443
220,641
istresearch/scrapy-cluster
redis-monitor/plugins/expire_monitor.py
ExpireMonitor.check_precondition
def check_precondition(self, key, value): ''' Override to check for timeout ''' timeout = float(value) curr_time = self.get_current_time() if curr_time > timeout: return True return False
python
def check_precondition(self, key, value): ''' Override to check for timeout ''' timeout = float(value) curr_time = self.get_current_time() if curr_time > timeout: return True return False
[ "def", "check_precondition", "(", "self", ",", "key", ",", "value", ")", ":", "timeout", "=", "float", "(", "value", ")", "curr_time", "=", "self", ".", "get_current_time", "(", ")", "if", "curr_time", ">", "timeout", ":", "return", "True", "return", "Fa...
Override to check for timeout
[ "Override", "to", "check", "for", "timeout" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/redis-monitor/plugins/expire_monitor.py#L18-L26
220,642
istresearch/scrapy-cluster
utils/scutils/stats_collector.py
StatsCollector.get_time_window
def get_time_window(self, redis_conn=None, host='localhost', port=6379, key='time_window_counter', cycle_time=5, start_time=None, window=SECONDS_1_HOUR, roll=True, keep_max=12): ''' Generate a new TimeWindow Useful for colle...
python
def get_time_window(self, redis_conn=None, host='localhost', port=6379, key='time_window_counter', cycle_time=5, start_time=None, window=SECONDS_1_HOUR, roll=True, keep_max=12): ''' Generate a new TimeWindow Useful for colle...
[ "def", "get_time_window", "(", "self", ",", "redis_conn", "=", "None", ",", "host", "=", "'localhost'", ",", "port", "=", "6379", ",", "key", "=", "'time_window_counter'", ",", "cycle_time", "=", "5", ",", "start_time", "=", "None", ",", "window", "=", "...
Generate a new TimeWindow Useful for collecting number of hits generated between certain times @param redis_conn: A premade redis connection (overrides host and port) @param host: the redis host @param port: the redis port @param key: the key for your stats collection @p...
[ "Generate", "a", "new", "TimeWindow", "Useful", "for", "collecting", "number", "of", "hits", "generated", "between", "certain", "times" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/utils/scutils/stats_collector.py#L43-L67
220,643
istresearch/scrapy-cluster
utils/scutils/stats_collector.py
StatsCollector.get_rolling_time_window
def get_rolling_time_window(self, redis_conn=None, host='localhost', port=6379, key='rolling_time_window_counter', cycle_time=5, window=SECONDS_1_HOUR): ''' Generate a new RollingTimeWindow Useful for collect data about the number o...
python
def get_rolling_time_window(self, redis_conn=None, host='localhost', port=6379, key='rolling_time_window_counter', cycle_time=5, window=SECONDS_1_HOUR): ''' Generate a new RollingTimeWindow Useful for collect data about the number o...
[ "def", "get_rolling_time_window", "(", "self", ",", "redis_conn", "=", "None", ",", "host", "=", "'localhost'", ",", "port", "=", "6379", ",", "key", "=", "'rolling_time_window_counter'", ",", "cycle_time", "=", "5", ",", "window", "=", "SECONDS_1_HOUR", ")", ...
Generate a new RollingTimeWindow Useful for collect data about the number of hits in the past X seconds @param redis_conn: A premade redis connection (overrides host and port) @param host: the redis host @param port: the redis port @param key: the key for your stats collection ...
[ "Generate", "a", "new", "RollingTimeWindow", "Useful", "for", "collect", "data", "about", "the", "number", "of", "hits", "in", "the", "past", "X", "seconds" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/utils/scutils/stats_collector.py#L70-L87
220,644
istresearch/scrapy-cluster
utils/scutils/stats_collector.py
StatsCollector.get_counter
def get_counter(self, redis_conn=None, host='localhost', port=6379, key='counter', cycle_time=5, start_time=None, window=SECONDS_1_HOUR, roll=True, keep_max=12, start_at=0): ''' Generate a new Counter Useful for generic distributed counters @param...
python
def get_counter(self, redis_conn=None, host='localhost', port=6379, key='counter', cycle_time=5, start_time=None, window=SECONDS_1_HOUR, roll=True, keep_max=12, start_at=0): ''' Generate a new Counter Useful for generic distributed counters @param...
[ "def", "get_counter", "(", "self", ",", "redis_conn", "=", "None", ",", "host", "=", "'localhost'", ",", "port", "=", "6379", ",", "key", "=", "'counter'", ",", "cycle_time", "=", "5", ",", "start_time", "=", "None", ",", "window", "=", "SECONDS_1_HOUR",...
Generate a new Counter Useful for generic distributed counters @param redis_conn: A premade redis connection (overrides host and port) @param host: the redis host @param port: the redis port @param key: the key for your stats collection @param cycle_time: how often to ch...
[ "Generate", "a", "new", "Counter", "Useful", "for", "generic", "distributed", "counters" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/utils/scutils/stats_collector.py#L90-L114
220,645
istresearch/scrapy-cluster
utils/scutils/stats_collector.py
StatsCollector.get_unique_counter
def get_unique_counter(self, redis_conn=None, host='localhost', port=6379, key='unique_counter', cycle_time=5, start_time=None, window=SECONDS_1_HOUR, roll=True, keep_max=12): ''' Generate a new UniqueCounter. Useful for exactly counting uniq...
python
def get_unique_counter(self, redis_conn=None, host='localhost', port=6379, key='unique_counter', cycle_time=5, start_time=None, window=SECONDS_1_HOUR, roll=True, keep_max=12): ''' Generate a new UniqueCounter. Useful for exactly counting uniq...
[ "def", "get_unique_counter", "(", "self", ",", "redis_conn", "=", "None", ",", "host", "=", "'localhost'", ",", "port", "=", "6379", ",", "key", "=", "'unique_counter'", ",", "cycle_time", "=", "5", ",", "start_time", "=", "None", ",", "window", "=", "SE...
Generate a new UniqueCounter. Useful for exactly counting unique objects @param redis_conn: A premade redis connection (overrides host and port) @param host: the redis host @param port: the redis port @param key: the key for your stats collection @param cycle_time: how o...
[ "Generate", "a", "new", "UniqueCounter", ".", "Useful", "for", "exactly", "counting", "unique", "objects" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/utils/scutils/stats_collector.py#L117-L140
220,646
istresearch/scrapy-cluster
utils/scutils/stats_collector.py
StatsCollector.get_hll_counter
def get_hll_counter(self, redis_conn=None, host='localhost', port=6379, key='hyperloglog_counter', cycle_time=5, start_time=None, window=SECONDS_1_HOUR, roll=True, keep_max=12): ''' Generate a new HyperLogLogCounter. Useful ...
python
def get_hll_counter(self, redis_conn=None, host='localhost', port=6379, key='hyperloglog_counter', cycle_time=5, start_time=None, window=SECONDS_1_HOUR, roll=True, keep_max=12): ''' Generate a new HyperLogLogCounter. Useful ...
[ "def", "get_hll_counter", "(", "self", ",", "redis_conn", "=", "None", ",", "host", "=", "'localhost'", ",", "port", "=", "6379", ",", "key", "=", "'hyperloglog_counter'", ",", "cycle_time", "=", "5", ",", "start_time", "=", "None", ",", "window", "=", "...
Generate a new HyperLogLogCounter. Useful for approximating extremely large counts of unique items @param redis_conn: A premade redis connection (overrides host and port) @param host: the redis host @param port: the redis port @param key: the key for your stats collection ...
[ "Generate", "a", "new", "HyperLogLogCounter", ".", "Useful", "for", "approximating", "extremely", "large", "counts", "of", "unique", "items" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/utils/scutils/stats_collector.py#L143-L167
220,647
istresearch/scrapy-cluster
utils/scutils/stats_collector.py
AbstractCounter.setup
def setup(self, redis_conn=None, host='localhost', port=6379): ''' Set up the redis connection ''' if redis_conn is None: if host is not None and port is not None: self.redis_conn = redis.Redis(host=host, port=port) else: raise Exce...
python
def setup(self, redis_conn=None, host='localhost', port=6379): ''' Set up the redis connection ''' if redis_conn is None: if host is not None and port is not None: self.redis_conn = redis.Redis(host=host, port=port) else: raise Exce...
[ "def", "setup", "(", "self", ",", "redis_conn", "=", "None", ",", "host", "=", "'localhost'", ",", "port", "=", "6379", ")", ":", "if", "redis_conn", "is", "None", ":", "if", "host", "is", "not", "None", "and", "port", "is", "not", "None", ":", "se...
Set up the redis connection
[ "Set", "up", "the", "redis", "connection" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/utils/scutils/stats_collector.py#L206-L219
220,648
istresearch/scrapy-cluster
utils/scutils/stats_collector.py
ThreadedCounter.setup
def setup(self, redis_conn=None, host='localhost', port=6379): ''' Set up the counting manager class @param redis_conn: A premade redis connection (overrides host and port) @param host: the redis host @param port: the redis port ''' AbstractCounter.setup(self, re...
python
def setup(self, redis_conn=None, host='localhost', port=6379): ''' Set up the counting manager class @param redis_conn: A premade redis connection (overrides host and port) @param host: the redis host @param port: the redis port ''' AbstractCounter.setup(self, re...
[ "def", "setup", "(", "self", ",", "redis_conn", "=", "None", ",", "host", "=", "'localhost'", ",", "port", "=", "6379", ")", ":", "AbstractCounter", ".", "setup", "(", "self", ",", "redis_conn", "=", "redis_conn", ",", "host", "=", "host", ",", "port",...
Set up the counting manager class @param redis_conn: A premade redis connection (overrides host and port) @param host: the redis host @param port: the redis port
[ "Set", "up", "the", "counting", "manager", "class" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/utils/scutils/stats_collector.py#L300-L311
220,649
istresearch/scrapy-cluster
utils/scutils/stats_collector.py
ThreadedCounter._threaded_start
def _threaded_start(self): ''' Spawns a worker thread to do the expiration checks ''' self.active = True self.thread = Thread(target=self._main_loop) self.thread.setDaemon(True) self.thread.start()
python
def _threaded_start(self): ''' Spawns a worker thread to do the expiration checks ''' self.active = True self.thread = Thread(target=self._main_loop) self.thread.setDaemon(True) self.thread.start()
[ "def", "_threaded_start", "(", "self", ")", ":", "self", ".", "active", "=", "True", "self", ".", "thread", "=", "Thread", "(", "target", "=", "self", ".", "_main_loop", ")", "self", ".", "thread", ".", "setDaemon", "(", "True", ")", "self", ".", "th...
Spawns a worker thread to do the expiration checks
[ "Spawns", "a", "worker", "thread", "to", "do", "the", "expiration", "checks" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/utils/scutils/stats_collector.py#L313-L320
220,650
istresearch/scrapy-cluster
utils/scutils/stats_collector.py
ThreadedCounter._main_loop
def _main_loop(self): ''' Main loop for the stats collector ''' while self.active: self.expire() if self.roll and self.is_expired(): self.start_time = self.start_time + self.window self._set_key() self.purge_old() ...
python
def _main_loop(self): ''' Main loop for the stats collector ''' while self.active: self.expire() if self.roll and self.is_expired(): self.start_time = self.start_time + self.window self._set_key() self.purge_old() ...
[ "def", "_main_loop", "(", "self", ")", ":", "while", "self", ".", "active", ":", "self", ".", "expire", "(", ")", "if", "self", ".", "roll", "and", "self", ".", "is_expired", "(", ")", ":", "self", ".", "start_time", "=", "self", ".", "start_time", ...
Main loop for the stats collector
[ "Main", "loop", "for", "the", "stats", "collector" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/utils/scutils/stats_collector.py#L329-L340
220,651
istresearch/scrapy-cluster
utils/scutils/stats_collector.py
ThreadedCounter._set_key
def _set_key(self): ''' sets the final key to be used currently ''' if self.roll: self.date = time.strftime(self.date_format, time.gmtime(self.start_time)) self.final_key = '{}:{}'.format(self.key, self.date) else: ...
python
def _set_key(self): ''' sets the final key to be used currently ''' if self.roll: self.date = time.strftime(self.date_format, time.gmtime(self.start_time)) self.final_key = '{}:{}'.format(self.key, self.date) else: ...
[ "def", "_set_key", "(", "self", ")", ":", "if", "self", ".", "roll", ":", "self", ".", "date", "=", "time", ".", "strftime", "(", "self", ".", "date_format", ",", "time", ".", "gmtime", "(", "self", ".", "start_time", ")", ")", "self", ".", "final_...
sets the final key to be used currently
[ "sets", "the", "final", "key", "to", "be", "used", "currently" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/utils/scutils/stats_collector.py#L348-L358
220,652
istresearch/scrapy-cluster
utils/scutils/stats_collector.py
ThreadedCounter.is_expired
def is_expired(self): ''' Returns true if the time is beyond the window ''' if self.window is not None: return (self._time() - self.start_time) >= self.window return False
python
def is_expired(self): ''' Returns true if the time is beyond the window ''' if self.window is not None: return (self._time() - self.start_time) >= self.window return False
[ "def", "is_expired", "(", "self", ")", ":", "if", "self", ".", "window", "is", "not", "None", ":", "return", "(", "self", ".", "_time", "(", ")", "-", "self", ".", "start_time", ")", ">=", "self", ".", "window", "return", "False" ]
Returns true if the time is beyond the window
[ "Returns", "true", "if", "the", "time", "is", "beyond", "the", "window" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/utils/scutils/stats_collector.py#L360-L366
220,653
istresearch/scrapy-cluster
utils/scutils/stats_collector.py
ThreadedCounter.purge_old
def purge_old(self): ''' Removes keys that are beyond our keep_max limit ''' if self.keep_max is not None: keys = self.redis_conn.keys(self.get_key() + ':*') keys.sort(reverse=True) while len(keys) > self.keep_max: key = keys.pop() ...
python
def purge_old(self): ''' Removes keys that are beyond our keep_max limit ''' if self.keep_max is not None: keys = self.redis_conn.keys(self.get_key() + ':*') keys.sort(reverse=True) while len(keys) > self.keep_max: key = keys.pop() ...
[ "def", "purge_old", "(", "self", ")", ":", "if", "self", ".", "keep_max", "is", "not", "None", ":", "keys", "=", "self", ".", "redis_conn", ".", "keys", "(", "self", ".", "get_key", "(", ")", "+", "':*'", ")", "keys", ".", "sort", "(", "reverse", ...
Removes keys that are beyond our keep_max limit
[ "Removes", "keys", "that", "are", "beyond", "our", "keep_max", "limit" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/utils/scutils/stats_collector.py#L368-L377
220,654
istresearch/scrapy-cluster
utils/scutils/redis_queue.py
Base._encode_item
def _encode_item(self, item): ''' Encode an item object @requires: The object be serializable ''' if self.encoding.__name__ == 'pickle': return self.encoding.dumps(item, protocol=-1) else: return self.encoding.dumps(item)
python
def _encode_item(self, item): ''' Encode an item object @requires: The object be serializable ''' if self.encoding.__name__ == 'pickle': return self.encoding.dumps(item, protocol=-1) else: return self.encoding.dumps(item)
[ "def", "_encode_item", "(", "self", ",", "item", ")", ":", "if", "self", ".", "encoding", ".", "__name__", "==", "'pickle'", ":", "return", "self", ".", "encoding", ".", "dumps", "(", "item", ",", "protocol", "=", "-", "1", ")", "else", ":", "return"...
Encode an item object @requires: The object be serializable
[ "Encode", "an", "item", "object" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/utils/scutils/redis_queue.py#L35-L44
220,655
istresearch/scrapy-cluster
utils/scutils/zookeeper_watcher.py
ZookeeperWatcher.threaded_start
def threaded_start(self, no_init=False): ''' Spawns a worker thread to set up the zookeeper connection ''' thread = Thread(target=self.init_connections, kwargs={ 'no_init': no_init}) thread.setDaemon(True) thread.start() thread.join()
python
def threaded_start(self, no_init=False): ''' Spawns a worker thread to set up the zookeeper connection ''' thread = Thread(target=self.init_connections, kwargs={ 'no_init': no_init}) thread.setDaemon(True) thread.start() thread.join()
[ "def", "threaded_start", "(", "self", ",", "no_init", "=", "False", ")", ":", "thread", "=", "Thread", "(", "target", "=", "self", ".", "init_connections", ",", "kwargs", "=", "{", "'no_init'", ":", "no_init", "}", ")", "thread", ".", "setDaemon", "(", ...
Spawns a worker thread to set up the zookeeper connection
[ "Spawns", "a", "worker", "thread", "to", "set", "up", "the", "zookeeper", "connection" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/utils/scutils/zookeeper_watcher.py#L77-L85
220,656
istresearch/scrapy-cluster
utils/scutils/zookeeper_watcher.py
ZookeeperWatcher.init_connections
def init_connections(self, no_init=False): ''' Sets up the initial Kazoo Client and watches ''' success = False self.set_valid(False) if not no_init: if self.zoo_client: self.zoo_client.remove_listener(self.state_listener) self...
python
def init_connections(self, no_init=False): ''' Sets up the initial Kazoo Client and watches ''' success = False self.set_valid(False) if not no_init: if self.zoo_client: self.zoo_client.remove_listener(self.state_listener) self...
[ "def", "init_connections", "(", "self", ",", "no_init", "=", "False", ")", ":", "success", "=", "False", "self", ".", "set_valid", "(", "False", ")", "if", "not", "no_init", ":", "if", "self", ".", "zoo_client", ":", "self", ".", "zoo_client", ".", "re...
Sets up the initial Kazoo Client and watches
[ "Sets", "up", "the", "initial", "Kazoo", "Client", "and", "watches" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/utils/scutils/zookeeper_watcher.py#L87-L121
220,657
istresearch/scrapy-cluster
utils/scutils/zookeeper_watcher.py
ZookeeperWatcher.setup
def setup(self): ''' Ensures the path to the watched file exists and we have a state listener ''' self.zoo_client.add_listener(self.state_listener) if self.ensure: self.zoo_client.ensure_path(self.my_file)
python
def setup(self): ''' Ensures the path to the watched file exists and we have a state listener ''' self.zoo_client.add_listener(self.state_listener) if self.ensure: self.zoo_client.ensure_path(self.my_file)
[ "def", "setup", "(", "self", ")", ":", "self", ".", "zoo_client", ".", "add_listener", "(", "self", ".", "state_listener", ")", "if", "self", ".", "ensure", ":", "self", ".", "zoo_client", ".", "ensure_path", "(", "self", ".", "my_file", ")" ]
Ensures the path to the watched file exists and we have a state listener
[ "Ensures", "the", "path", "to", "the", "watched", "file", "exists", "and", "we", "have", "a", "state", "listener" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/utils/scutils/zookeeper_watcher.py#L123-L131
220,658
istresearch/scrapy-cluster
utils/scutils/zookeeper_watcher.py
ZookeeperWatcher.state_listener
def state_listener(self, state): ''' Restarts the session if we get anything besides CONNECTED ''' if state == KazooState.SUSPENDED: self.set_valid(False) self.call_error(self.BAD_CONNECTION) elif state == KazooState.LOST and not self.do_not_restart: ...
python
def state_listener(self, state): ''' Restarts the session if we get anything besides CONNECTED ''' if state == KazooState.SUSPENDED: self.set_valid(False) self.call_error(self.BAD_CONNECTION) elif state == KazooState.LOST and not self.do_not_restart: ...
[ "def", "state_listener", "(", "self", ",", "state", ")", ":", "if", "state", "==", "KazooState", ".", "SUSPENDED", ":", "self", ".", "set_valid", "(", "False", ")", "self", ".", "call_error", "(", "self", ".", "BAD_CONNECTION", ")", "elif", "state", "=="...
Restarts the session if we get anything besides CONNECTED
[ "Restarts", "the", "session", "if", "we", "get", "anything", "besides", "CONNECTED" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/utils/scutils/zookeeper_watcher.py#L133-L146
220,659
istresearch/scrapy-cluster
utils/scutils/zookeeper_watcher.py
ZookeeperWatcher.close
def close(self, kill_restart=True): ''' Use when you would like to close everything down @param kill_restart= Prevent kazoo restarting from occurring ''' self.do_not_restart = kill_restart self.zoo_client.stop() self.zoo_client.close()
python
def close(self, kill_restart=True): ''' Use when you would like to close everything down @param kill_restart= Prevent kazoo restarting from occurring ''' self.do_not_restart = kill_restart self.zoo_client.stop() self.zoo_client.close()
[ "def", "close", "(", "self", ",", "kill_restart", "=", "True", ")", ":", "self", ".", "do_not_restart", "=", "kill_restart", "self", ".", "zoo_client", ".", "stop", "(", ")", "self", ".", "zoo_client", ".", "close", "(", ")" ]
Use when you would like to close everything down @param kill_restart= Prevent kazoo restarting from occurring
[ "Use", "when", "you", "would", "like", "to", "close", "everything", "down" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/utils/scutils/zookeeper_watcher.py#L166-L173
220,660
istresearch/scrapy-cluster
utils/scutils/zookeeper_watcher.py
ZookeeperWatcher.get_file_contents
def get_file_contents(self, pointer=False): ''' Gets any file contents you care about. Defaults to the main file @param pointer: The the contents of the file pointer, not the pointed at file @return: A string of the contents ''' if self.pointer: if poi...
python
def get_file_contents(self, pointer=False): ''' Gets any file contents you care about. Defaults to the main file @param pointer: The the contents of the file pointer, not the pointed at file @return: A string of the contents ''' if self.pointer: if poi...
[ "def", "get_file_contents", "(", "self", ",", "pointer", "=", "False", ")", ":", "if", "self", ".", "pointer", ":", "if", "pointer", ":", "return", "self", ".", "old_pointed", "else", ":", "return", "self", ".", "old_data", "else", ":", "return", "self",...
Gets any file contents you care about. Defaults to the main file @param pointer: The the contents of the file pointer, not the pointed at file @return: A string of the contents
[ "Gets", "any", "file", "contents", "you", "care", "about", ".", "Defaults", "to", "the", "main", "file" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/utils/scutils/zookeeper_watcher.py#L175-L188
220,661
istresearch/scrapy-cluster
utils/scutils/zookeeper_watcher.py
ZookeeperWatcher.update_file
def update_file(self, path): ''' Updates the file watcher and calls the appropriate method for results @return: False if we need to keep trying the connection ''' try: # grab the file result, stat = self.zoo_client.get(path, watch=self.watch_file) ...
python
def update_file(self, path): ''' Updates the file watcher and calls the appropriate method for results @return: False if we need to keep trying the connection ''' try: # grab the file result, stat = self.zoo_client.get(path, watch=self.watch_file) ...
[ "def", "update_file", "(", "self", ",", "path", ")", ":", "try", ":", "# grab the file", "result", ",", "stat", "=", "self", ".", "zoo_client", ".", "get", "(", "path", ",", "watch", "=", "self", ".", "watch_file", ")", "except", "ZookeeperError", ":", ...
Updates the file watcher and calls the appropriate method for results @return: False if we need to keep trying the connection
[ "Updates", "the", "file", "watcher", "and", "calls", "the", "appropriate", "method", "for", "results" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/utils/scutils/zookeeper_watcher.py#L197-L229
220,662
istresearch/scrapy-cluster
utils/scutils/zookeeper_watcher.py
ZookeeperWatcher.update_pointed
def update_pointed(self): ''' Grabs the latest file contents based on the pointer uri ''' # only grab file if our pointer is still good (not None) if not self.pointed_at_expired: try: conf_string, stat2 = self.zoo_client.get(self.point_path, ...
python
def update_pointed(self): ''' Grabs the latest file contents based on the pointer uri ''' # only grab file if our pointer is still good (not None) if not self.pointed_at_expired: try: conf_string, stat2 = self.zoo_client.get(self.point_path, ...
[ "def", "update_pointed", "(", "self", ")", ":", "# only grab file if our pointer is still good (not None)", "if", "not", "self", ".", "pointed_at_expired", ":", "try", ":", "conf_string", ",", "stat2", "=", "self", ".", "zoo_client", ".", "get", "(", "self", ".", ...
Grabs the latest file contents based on the pointer uri
[ "Grabs", "the", "latest", "file", "contents", "based", "on", "the", "pointer", "uri" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/utils/scutils/zookeeper_watcher.py#L237-L255
220,663
istresearch/scrapy-cluster
utils/scutils/zookeeper_watcher.py
ZookeeperWatcher.set_valid
def set_valid(self, boolean): ''' Sets the state and calls the change if needed @param bool: The state (true or false) ''' old_state = self.is_valid() self.valid_file = boolean if old_state != self.valid_file: self.call_valid(self.valid_file)
python
def set_valid(self, boolean): ''' Sets the state and calls the change if needed @param bool: The state (true or false) ''' old_state = self.is_valid() self.valid_file = boolean if old_state != self.valid_file: self.call_valid(self.valid_file)
[ "def", "set_valid", "(", "self", ",", "boolean", ")", ":", "old_state", "=", "self", ".", "is_valid", "(", ")", "self", ".", "valid_file", "=", "boolean", "if", "old_state", "!=", "self", ".", "valid_file", ":", "self", ".", "call_valid", "(", "self", ...
Sets the state and calls the change if needed @param bool: The state (true or false)
[ "Sets", "the", "state", "and", "calls", "the", "change", "if", "needed" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/utils/scutils/zookeeper_watcher.py#L257-L266
220,664
istresearch/scrapy-cluster
kafka-monitor/plugins/zookeeper_handler.py
ZookeeperHandler.setup
def setup(self, settings): ''' Setup redis and tldextract ''' self.extract = tldextract.TLDExtract() self.redis_conn = redis.Redis(host=settings['REDIS_HOST'], port=settings['REDIS_PORT'], db=settings.get...
python
def setup(self, settings): ''' Setup redis and tldextract ''' self.extract = tldextract.TLDExtract() self.redis_conn = redis.Redis(host=settings['REDIS_HOST'], port=settings['REDIS_PORT'], db=settings.get...
[ "def", "setup", "(", "self", ",", "settings", ")", ":", "self", ".", "extract", "=", "tldextract", ".", "TLDExtract", "(", ")", "self", ".", "redis_conn", "=", "redis", ".", "Redis", "(", "host", "=", "settings", "[", "'REDIS_HOST'", "]", ",", "port", ...
Setup redis and tldextract
[ "Setup", "redis", "and", "tldextract" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/kafka-monitor/plugins/zookeeper_handler.py#L14-L29
220,665
istresearch/scrapy-cluster
redis-monitor/plugins/base_monitor.py
BaseMonitor.get_log_dict
def get_log_dict(self, action, appid, spiderid=None, uuid=None, crawlid=None): ''' Returns a basic dictionary for logging @param action: the action taken by the redis monitor @param spiderid: the spider id @param appid: the application id @param uuid:...
python
def get_log_dict(self, action, appid, spiderid=None, uuid=None, crawlid=None): ''' Returns a basic dictionary for logging @param action: the action taken by the redis monitor @param spiderid: the spider id @param appid: the application id @param uuid:...
[ "def", "get_log_dict", "(", "self", ",", "action", ",", "appid", ",", "spiderid", "=", "None", ",", "uuid", "=", "None", ",", "crawlid", "=", "None", ")", ":", "extras", "=", "{", "}", "extras", "[", "'action'", "]", "=", "action", "extras", "[", "...
Returns a basic dictionary for logging @param action: the action taken by the redis monitor @param spiderid: the spider id @param appid: the application id @param uuid: a unique id of the request @param crawlid: a unique crawl id of the request
[ "Returns", "a", "basic", "dictionary", "for", "logging" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/redis-monitor/plugins/base_monitor.py#L71-L91
220,666
istresearch/scrapy-cluster
redis-monitor/redis_monitor.py
RedisMonitor._load_plugins
def _load_plugins(self): ''' Sets up all plugins and defaults ''' plugins = self.settings['PLUGINS'] self.plugins_dict = {} for key in plugins: # skip loading the plugin if its value is None if plugins[key] is None: continue ...
python
def _load_plugins(self): ''' Sets up all plugins and defaults ''' plugins = self.settings['PLUGINS'] self.plugins_dict = {} for key in plugins: # skip loading the plugin if its value is None if plugins[key] is None: continue ...
[ "def", "_load_plugins", "(", "self", ")", ":", "plugins", "=", "self", ".", "settings", "[", "'PLUGINS'", "]", "self", ".", "plugins_dict", "=", "{", "}", "for", "key", "in", "plugins", ":", "# skip loading the plugin if its value is None", "if", "plugins", "[...
Sets up all plugins and defaults
[ "Sets", "up", "all", "plugins", "and", "defaults" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/redis-monitor/redis_monitor.py#L87-L119
220,667
istresearch/scrapy-cluster
redis-monitor/redis_monitor.py
RedisMonitor._main_loop
def _main_loop(self): ''' The internal while true main loop for the redis monitor ''' self.logger.debug("Running main loop") old_time = 0 while True: for plugin_key in self.plugins_dict: obj = self.plugins_dict[plugin_key] self....
python
def _main_loop(self): ''' The internal while true main loop for the redis monitor ''' self.logger.debug("Running main loop") old_time = 0 while True: for plugin_key in self.plugins_dict: obj = self.plugins_dict[plugin_key] self....
[ "def", "_main_loop", "(", "self", ")", ":", "self", ".", "logger", ".", "debug", "(", "\"Running main loop\"", ")", "old_time", "=", "0", "while", "True", ":", "for", "plugin_key", "in", "self", ".", "plugins_dict", ":", "obj", "=", "self", ".", "plugins...
The internal while true main loop for the redis monitor
[ "The", "internal", "while", "true", "main", "loop", "for", "the", "redis", "monitor" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/redis-monitor/redis_monitor.py#L127-L152
220,668
istresearch/scrapy-cluster
redis-monitor/redis_monitor.py
RedisMonitor._process_plugin
def _process_plugin(self, plugin): ''' Logic to handle each plugin that is active @param plugin: a plugin dict object ''' instance = plugin['instance'] regex = plugin['regex'] for key in self.redis_conn.scan_iter(match=regex): # acquire lock ...
python
def _process_plugin(self, plugin): ''' Logic to handle each plugin that is active @param plugin: a plugin dict object ''' instance = plugin['instance'] regex = plugin['regex'] for key in self.redis_conn.scan_iter(match=regex): # acquire lock ...
[ "def", "_process_plugin", "(", "self", ",", "plugin", ")", ":", "instance", "=", "plugin", "[", "'instance'", "]", "regex", "=", "plugin", "[", "'regex'", "]", "for", "key", "in", "self", ".", "redis_conn", ".", "scan_iter", "(", "match", "=", "regex", ...
Logic to handle each plugin that is active @param plugin: a plugin dict object
[ "Logic", "to", "handle", "each", "plugin", "that", "is", "active" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/redis-monitor/redis_monitor.py#L154-L179
220,669
istresearch/scrapy-cluster
redis-monitor/redis_monitor.py
RedisMonitor._create_lock_object
def _create_lock_object(self, key): ''' Returns a lock object, split for testing ''' return redis_lock.Lock(self.redis_conn, key, expire=self.settings['REDIS_LOCK_EXPIRATION'], auto_renewal=True)
python
def _create_lock_object(self, key): ''' Returns a lock object, split for testing ''' return redis_lock.Lock(self.redis_conn, key, expire=self.settings['REDIS_LOCK_EXPIRATION'], auto_renewal=True)
[ "def", "_create_lock_object", "(", "self", ",", "key", ")", ":", "return", "redis_lock", ".", "Lock", "(", "self", ".", "redis_conn", ",", "key", ",", "expire", "=", "self", ".", "settings", "[", "'REDIS_LOCK_EXPIRATION'", "]", ",", "auto_renewal", "=", "T...
Returns a lock object, split for testing
[ "Returns", "a", "lock", "object", "split", "for", "testing" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/redis-monitor/redis_monitor.py#L181-L187
220,670
istresearch/scrapy-cluster
redis-monitor/redis_monitor.py
RedisMonitor._process_failures
def _process_failures(self, key): ''' Handles the retrying of the failed key ''' if self.settings['RETRY_FAILURES']: self.logger.debug("going to retry failure") # get the current failure count failkey = self._get_fail_key(key) current = sel...
python
def _process_failures(self, key): ''' Handles the retrying of the failed key ''' if self.settings['RETRY_FAILURES']: self.logger.debug("going to retry failure") # get the current failure count failkey = self._get_fail_key(key) current = sel...
[ "def", "_process_failures", "(", "self", ",", "key", ")", ":", "if", "self", ".", "settings", "[", "'RETRY_FAILURES'", "]", ":", "self", ".", "logger", ".", "debug", "(", "\"going to retry failure\"", ")", "# get the current failure count", "failkey", "=", "self...
Handles the retrying of the failed key
[ "Handles", "the", "retrying", "of", "the", "failed", "key" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/redis-monitor/redis_monitor.py#L195-L216
220,671
istresearch/scrapy-cluster
redis-monitor/redis_monitor.py
RedisMonitor._setup_stats
def _setup_stats(self): ''' Sets up the stats ''' # stats setup self.stats_dict = {} if self.settings['STATS_TOTAL']: self._setup_stats_total() if self.settings['STATS_PLUGINS']: self._setup_stats_plugins()
python
def _setup_stats(self): ''' Sets up the stats ''' # stats setup self.stats_dict = {} if self.settings['STATS_TOTAL']: self._setup_stats_total() if self.settings['STATS_PLUGINS']: self._setup_stats_plugins()
[ "def", "_setup_stats", "(", "self", ")", ":", "# stats setup", "self", ".", "stats_dict", "=", "{", "}", "if", "self", ".", "settings", "[", "'STATS_TOTAL'", "]", ":", "self", ".", "_setup_stats_total", "(", ")", "if", "self", ".", "settings", "[", "'STA...
Sets up the stats
[ "Sets", "up", "the", "stats" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/redis-monitor/redis_monitor.py#L239-L250
220,672
istresearch/scrapy-cluster
redis-monitor/redis_monitor.py
RedisMonitor._setup_stats_plugins
def _setup_stats_plugins(self): ''' Sets up the plugin stats collectors ''' self.stats_dict['plugins'] = {} for key in self.plugins_dict: plugin_name = self.plugins_dict[key]['instance'].__class__.__name__ temp_key = 'stats:redis-monitor:{p}'.format(p=plug...
python
def _setup_stats_plugins(self): ''' Sets up the plugin stats collectors ''' self.stats_dict['plugins'] = {} for key in self.plugins_dict: plugin_name = self.plugins_dict[key]['instance'].__class__.__name__ temp_key = 'stats:redis-monitor:{p}'.format(p=plug...
[ "def", "_setup_stats_plugins", "(", "self", ")", ":", "self", ".", "stats_dict", "[", "'plugins'", "]", "=", "{", "}", "for", "key", "in", "self", ".", "plugins_dict", ":", "plugin_name", "=", "self", ".", "plugins_dict", "[", "key", "]", "[", "'instance...
Sets up the plugin stats collectors
[ "Sets", "up", "the", "plugin", "stats", "collectors" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/redis-monitor/redis_monitor.py#L292-L322
220,673
istresearch/scrapy-cluster
redis-monitor/redis_monitor.py
RedisMonitor._dump_crawl_stats
def _dump_crawl_stats(self): ''' Dumps flattened crawling stats so the spiders do not have to ''' extras = {} spiders = {} spider_set = set() total_spider_count = 0 keys = self.redis_conn.keys('stats:crawler:*:*:*') for key in keys: #...
python
def _dump_crawl_stats(self): ''' Dumps flattened crawling stats so the spiders do not have to ''' extras = {} spiders = {} spider_set = set() total_spider_count = 0 keys = self.redis_conn.keys('stats:crawler:*:*:*') for key in keys: #...
[ "def", "_dump_crawl_stats", "(", "self", ")", ":", "extras", "=", "{", "}", "spiders", "=", "{", "}", "spider_set", "=", "set", "(", ")", "total_spider_count", "=", "0", "keys", "=", "self", ".", "redis_conn", ".", "keys", "(", "'stats:crawler:*:*:*'", "...
Dumps flattened crawling stats so the spiders do not have to
[ "Dumps", "flattened", "crawling", "stats", "so", "the", "spiders", "do", "not", "have", "to" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/redis-monitor/redis_monitor.py#L398-L451
220,674
istresearch/scrapy-cluster
redis-monitor/redis_monitor.py
RedisMonitor._dump_queue_stats
def _dump_queue_stats(self): ''' Dumps basic info about the queue lengths for the spider types ''' extras = {} keys = self.redis_conn.keys('*:*:queue') total_backlog = 0 for key in keys: elements = key.split(":") spider = elements[0] ...
python
def _dump_queue_stats(self): ''' Dumps basic info about the queue lengths for the spider types ''' extras = {} keys = self.redis_conn.keys('*:*:queue') total_backlog = 0 for key in keys: elements = key.split(":") spider = elements[0] ...
[ "def", "_dump_queue_stats", "(", "self", ")", ":", "extras", "=", "{", "}", "keys", "=", "self", ".", "redis_conn", ".", "keys", "(", "'*:*:queue'", ")", "total_backlog", "=", "0", "for", "key", "in", "keys", ":", "elements", "=", "key", ".", "split", ...
Dumps basic info about the queue lengths for the spider types
[ "Dumps", "basic", "info", "about", "the", "queue", "lengths", "for", "the", "spider", "types" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/redis-monitor/redis_monitor.py#L453-L482
220,675
istresearch/scrapy-cluster
redis-monitor/redis_monitor.py
RedisMonitor.close
def close(self): ''' Closes the Redis Monitor and plugins ''' for plugin_key in self.plugins_dict: obj = self.plugins_dict[plugin_key] instance = obj['instance'] instance.close()
python
def close(self): ''' Closes the Redis Monitor and plugins ''' for plugin_key in self.plugins_dict: obj = self.plugins_dict[plugin_key] instance = obj['instance'] instance.close()
[ "def", "close", "(", "self", ")", ":", "for", "plugin_key", "in", "self", ".", "plugins_dict", ":", "obj", "=", "self", ".", "plugins_dict", "[", "plugin_key", "]", "instance", "=", "obj", "[", "'instance'", "]", "instance", ".", "close", "(", ")" ]
Closes the Redis Monitor and plugins
[ "Closes", "the", "Redis", "Monitor", "and", "plugins" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/redis-monitor/redis_monitor.py#L494-L501
220,676
istresearch/scrapy-cluster
redis-monitor/plugins/stats_monitor.py
StatsMonitor.get_all_stats
def get_all_stats(self): ''' Gather all stats objects ''' self.logger.debug("Gathering all stats") the_dict = {} the_dict['kafka-monitor'] = self.get_kafka_monitor_stats() the_dict['redis-monitor'] = self.get_redis_monitor_stats() the_dict['crawler'] = sel...
python
def get_all_stats(self): ''' Gather all stats objects ''' self.logger.debug("Gathering all stats") the_dict = {} the_dict['kafka-monitor'] = self.get_kafka_monitor_stats() the_dict['redis-monitor'] = self.get_redis_monitor_stats() the_dict['crawler'] = sel...
[ "def", "get_all_stats", "(", "self", ")", ":", "self", ".", "logger", ".", "debug", "(", "\"Gathering all stats\"", ")", "the_dict", "=", "{", "}", "the_dict", "[", "'kafka-monitor'", "]", "=", "self", ".", "get_kafka_monitor_stats", "(", ")", "the_dict", "[...
Gather all stats objects
[ "Gather", "all", "stats", "objects" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/redis-monitor/plugins/stats_monitor.py#L69-L80
220,677
istresearch/scrapy-cluster
redis-monitor/plugins/stats_monitor.py
StatsMonitor._get_plugin_stats
def _get_plugin_stats(self, name): ''' Used for getting stats for Plugin based stuff, like Kafka Monitor and Redis Monitor @param name: the main class stats name @return: A formatted dict of stats ''' the_dict = {} keys = self.redis_conn.keys('stats:{n}:...
python
def _get_plugin_stats(self, name): ''' Used for getting stats for Plugin based stuff, like Kafka Monitor and Redis Monitor @param name: the main class stats name @return: A formatted dict of stats ''' the_dict = {} keys = self.redis_conn.keys('stats:{n}:...
[ "def", "_get_plugin_stats", "(", "self", ",", "name", ")", ":", "the_dict", "=", "{", "}", "keys", "=", "self", ".", "redis_conn", ".", "keys", "(", "'stats:{n}:*'", ".", "format", "(", "n", "=", "name", ")", ")", "for", "key", "in", "keys", ":", "...
Used for getting stats for Plugin based stuff, like Kafka Monitor and Redis Monitor @param name: the main class stats name @return: A formatted dict of stats
[ "Used", "for", "getting", "stats", "for", "Plugin", "based", "stuff", "like", "Kafka", "Monitor", "and", "Redis", "Monitor" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/redis-monitor/plugins/stats_monitor.py#L109-L146
220,678
istresearch/scrapy-cluster
redis-monitor/plugins/stats_monitor.py
StatsMonitor._get_key_value
def _get_key_value(self, key, is_hll=False): ''' Returns the proper key value for the stats @param key: the redis key @param is_hll: the key is a HyperLogLog, else is a sorted set ''' if is_hll: # get hll value return self.redis_conn.execute_comma...
python
def _get_key_value(self, key, is_hll=False): ''' Returns the proper key value for the stats @param key: the redis key @param is_hll: the key is a HyperLogLog, else is a sorted set ''' if is_hll: # get hll value return self.redis_conn.execute_comma...
[ "def", "_get_key_value", "(", "self", ",", "key", ",", "is_hll", "=", "False", ")", ":", "if", "is_hll", ":", "# get hll value", "return", "self", ".", "redis_conn", ".", "execute_command", "(", "\"PFCOUNT\"", ",", "key", ")", "else", ":", "# get zcard value...
Returns the proper key value for the stats @param key: the redis key @param is_hll: the key is a HyperLogLog, else is a sorted set
[ "Returns", "the", "proper", "key", "value", "for", "the", "stats" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/redis-monitor/plugins/stats_monitor.py#L148-L160
220,679
istresearch/scrapy-cluster
redis-monitor/plugins/stats_monitor.py
StatsMonitor.get_crawler_stats
def get_crawler_stats(self): ''' Gather crawler stats @return: A dict of stats ''' self.logger.debug("Gathering crawler stats") the_dict = {} the_dict['spiders'] = self.get_spider_stats()['spiders'] the_dict['machines'] = self.get_machine_stats()['machin...
python
def get_crawler_stats(self): ''' Gather crawler stats @return: A dict of stats ''' self.logger.debug("Gathering crawler stats") the_dict = {} the_dict['spiders'] = self.get_spider_stats()['spiders'] the_dict['machines'] = self.get_machine_stats()['machin...
[ "def", "get_crawler_stats", "(", "self", ")", ":", "self", ".", "logger", ".", "debug", "(", "\"Gathering crawler stats\"", ")", "the_dict", "=", "{", "}", "the_dict", "[", "'spiders'", "]", "=", "self", ".", "get_spider_stats", "(", ")", "[", "'spiders'", ...
Gather crawler stats @return: A dict of stats
[ "Gather", "crawler", "stats" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/redis-monitor/plugins/stats_monitor.py#L246-L259
220,680
istresearch/scrapy-cluster
redis-monitor/plugins/stats_monitor.py
StatsMonitor.get_queue_stats
def get_queue_stats(self): ''' Gather queue stats @return: A dict of stats ''' self.logger.debug("Gathering queue based stats") the_dict = {} keys = self.redis_conn.keys('*:*:queue') total_backlog = 0 for key in keys: elements = key.s...
python
def get_queue_stats(self): ''' Gather queue stats @return: A dict of stats ''' self.logger.debug("Gathering queue based stats") the_dict = {} keys = self.redis_conn.keys('*:*:queue') total_backlog = 0 for key in keys: elements = key.s...
[ "def", "get_queue_stats", "(", "self", ")", ":", "self", ".", "logger", ".", "debug", "(", "\"Gathering queue based stats\"", ")", "the_dict", "=", "{", "}", "keys", "=", "self", ".", "redis_conn", ".", "keys", "(", "'*:*:queue'", ")", "total_backlog", "=", ...
Gather queue stats @return: A dict of stats
[ "Gather", "queue", "stats" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/redis-monitor/plugins/stats_monitor.py#L261-L297
220,681
istresearch/scrapy-cluster
crawler/config/file_pusher.py
main
def main(): ''' A manual configuration file pusher for the crawlers. This will update Zookeeper with the contents of the file specified in the args. ''' import argparse from kazoo.client import KazooClient parser = argparse.ArgumentParser( description="Crawler config file pusher...
python
def main(): ''' A manual configuration file pusher for the crawlers. This will update Zookeeper with the contents of the file specified in the args. ''' import argparse from kazoo.client import KazooClient parser = argparse.ArgumentParser( description="Crawler config file pusher...
[ "def", "main", "(", ")", ":", "import", "argparse", "from", "kazoo", ".", "client", "import", "KazooClient", "parser", "=", "argparse", ".", "ArgumentParser", "(", "description", "=", "\"Crawler config file pusher to Zookeeper\"", ")", "parser", ".", "add_argument",...
A manual configuration file pusher for the crawlers. This will update Zookeeper with the contents of the file specified in the args.
[ "A", "manual", "configuration", "file", "pusher", "for", "the", "crawlers", ".", "This", "will", "update", "Zookeeper", "with", "the", "contents", "of", "the", "file", "specified", "in", "the", "args", "." ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/crawler/config/file_pusher.py#L5-L54
220,682
istresearch/scrapy-cluster
utils/scutils/log_factory.py
LogCallbackMixin.is_subdict
def is_subdict(self, a,b): ''' Return True if a is a subdict of b ''' return all((k in b and b[k]==v) for k,v in a.iteritems())
python
def is_subdict(self, a,b): ''' Return True if a is a subdict of b ''' return all((k in b and b[k]==v) for k,v in a.iteritems())
[ "def", "is_subdict", "(", "self", ",", "a", ",", "b", ")", ":", "return", "all", "(", "(", "k", "in", "b", "and", "b", "[", "k", "]", "==", "v", ")", "for", "k", ",", "v", "in", "a", ".", "iteritems", "(", ")", ")" ]
Return True if a is a subdict of b
[ "Return", "True", "if", "a", "is", "a", "subdict", "of", "b" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/utils/scutils/log_factory.py#L62-L66
220,683
istresearch/scrapy-cluster
utils/scutils/log_factory.py
LogObject._check_log_level
def _check_log_level(self, level): ''' Ensures a valid log level @param level: the asked for level ''' if level not in list(self.level_dict.keys()): self.log_level = 'DEBUG' self.logger.warn("Unknown log level '{lev}', defaulting to DEBUG" ...
python
def _check_log_level(self, level): ''' Ensures a valid log level @param level: the asked for level ''' if level not in list(self.level_dict.keys()): self.log_level = 'DEBUG' self.logger.warn("Unknown log level '{lev}', defaulting to DEBUG" ...
[ "def", "_check_log_level", "(", "self", ",", "level", ")", ":", "if", "level", "not", "in", "list", "(", "self", ".", "level_dict", ".", "keys", "(", ")", ")", ":", "self", ".", "log_level", "=", "'DEBUG'", "self", ".", "logger", ".", "warn", "(", ...
Ensures a valid log level @param level: the asked for level
[ "Ensures", "a", "valid", "log", "level" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/utils/scutils/log_factory.py#L169-L178
220,684
istresearch/scrapy-cluster
utils/scutils/log_factory.py
LogObject._get_formatter
def _get_formatter(self, json): ''' Return the proper log formatter @param json: Boolean value ''' if json: return jsonlogger.JsonFormatter() else: return logging.Formatter(self.format_string)
python
def _get_formatter(self, json): ''' Return the proper log formatter @param json: Boolean value ''' if json: return jsonlogger.JsonFormatter() else: return logging.Formatter(self.format_string)
[ "def", "_get_formatter", "(", "self", ",", "json", ")", ":", "if", "json", ":", "return", "jsonlogger", ".", "JsonFormatter", "(", ")", "else", ":", "return", "logging", ".", "Formatter", "(", "self", ".", "format_string", ")" ]
Return the proper log formatter @param json: Boolean value
[ "Return", "the", "proper", "log", "formatter" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/utils/scutils/log_factory.py#L180-L189
220,685
istresearch/scrapy-cluster
utils/scutils/log_factory.py
LogObject.debug
def debug(self, message, extra={}): ''' Writes an error message to the log @param message: The message to write @param extra: The extras object to pass in ''' if self.level_dict['DEBUG'] >= self.level_dict[self.log_level]: extras = self.add_extras(extra, "DEB...
python
def debug(self, message, extra={}): ''' Writes an error message to the log @param message: The message to write @param extra: The extras object to pass in ''' if self.level_dict['DEBUG'] >= self.level_dict[self.log_level]: extras = self.add_extras(extra, "DEB...
[ "def", "debug", "(", "self", ",", "message", ",", "extra", "=", "{", "}", ")", ":", "if", "self", ".", "level_dict", "[", "'DEBUG'", "]", ">=", "self", ".", "level_dict", "[", "self", ".", "log_level", "]", ":", "extras", "=", "self", ".", "add_ext...
Writes an error message to the log @param message: The message to write @param extra: The extras object to pass in
[ "Writes", "an", "error", "message", "to", "the", "log" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/utils/scutils/log_factory.py#L191-L201
220,686
istresearch/scrapy-cluster
utils/scutils/log_factory.py
LogObject._write_message
def _write_message(self, message, extra): ''' Writes the log output @param message: The message to write @param extra: The potential object to write ''' if not self.json: self._write_standard(message, extra) else: self._write_json(message, ...
python
def _write_message(self, message, extra): ''' Writes the log output @param message: The message to write @param extra: The potential object to write ''' if not self.json: self._write_standard(message, extra) else: self._write_json(message, ...
[ "def", "_write_message", "(", "self", ",", "message", ",", "extra", ")", ":", "if", "not", "self", ".", "json", ":", "self", ".", "_write_standard", "(", "message", ",", "extra", ")", "else", ":", "self", ".", "_write_json", "(", "message", ",", "extra...
Writes the log output @param message: The message to write @param extra: The potential object to write
[ "Writes", "the", "log", "output" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/utils/scutils/log_factory.py#L260-L269
220,687
istresearch/scrapy-cluster
utils/scutils/log_factory.py
LogObject._write_standard
def _write_standard(self, message, extra): ''' Writes a standard log statement @param message: The message to write @param extra: The object to pull defaults from ''' level = extra['level'] if self.include_extra: del extra['timestamp'] del...
python
def _write_standard(self, message, extra): ''' Writes a standard log statement @param message: The message to write @param extra: The object to pull defaults from ''' level = extra['level'] if self.include_extra: del extra['timestamp'] del...
[ "def", "_write_standard", "(", "self", ",", "message", ",", "extra", ")", ":", "level", "=", "extra", "[", "'level'", "]", "if", "self", ".", "include_extra", ":", "del", "extra", "[", "'timestamp'", "]", "del", "extra", "[", "'level'", "]", "del", "ex...
Writes a standard log statement @param message: The message to write @param extra: The object to pull defaults from
[ "Writes", "a", "standard", "log", "statement" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/utils/scutils/log_factory.py#L271-L297
220,688
istresearch/scrapy-cluster
utils/scutils/log_factory.py
LogObject._write_json
def _write_json(self, message, extra): ''' The JSON logger doesn't obey log levels @param message: The message to write @param extra: The object to write ''' self.logger.info(message, extra=extra)
python
def _write_json(self, message, extra): ''' The JSON logger doesn't obey log levels @param message: The message to write @param extra: The object to write ''' self.logger.info(message, extra=extra)
[ "def", "_write_json", "(", "self", ",", "message", ",", "extra", ")", ":", "self", ".", "logger", ".", "info", "(", "message", ",", "extra", "=", "extra", ")" ]
The JSON logger doesn't obey log levels @param message: The message to write @param extra: The object to write
[ "The", "JSON", "logger", "doesn", "t", "obey", "log", "levels" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/utils/scutils/log_factory.py#L299-L306
220,689
istresearch/scrapy-cluster
utils/scutils/log_factory.py
LogObject.add_extras
def add_extras(self, dict, level): ''' Adds the log level to the dict object ''' my_copy = copy.deepcopy(dict) if 'level' not in my_copy: my_copy['level'] = level if 'timestamp' not in my_copy: my_copy['timestamp'] = self._get_time() if 'lo...
python
def add_extras(self, dict, level): ''' Adds the log level to the dict object ''' my_copy = copy.deepcopy(dict) if 'level' not in my_copy: my_copy['level'] = level if 'timestamp' not in my_copy: my_copy['timestamp'] = self._get_time() if 'lo...
[ "def", "add_extras", "(", "self", ",", "dict", ",", "level", ")", ":", "my_copy", "=", "copy", ".", "deepcopy", "(", "dict", ")", "if", "'level'", "not", "in", "my_copy", ":", "my_copy", "[", "'level'", "]", "=", "level", "if", "'timestamp'", "not", ...
Adds the log level to the dict object
[ "Adds", "the", "log", "level", "to", "the", "dict", "object" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/utils/scutils/log_factory.py#L315-L326
220,690
istresearch/scrapy-cluster
crawler/crawling/log_retry_middleware.py
LogRetryMiddleware._increment_504_stat
def _increment_504_stat(self, request): ''' Increments the 504 stat counters @param request: The scrapy request in the spider ''' for key in self.stats_dict: if key == 'lifetime': unique = request.url + str(time.time()) self.stats_dict...
python
def _increment_504_stat(self, request): ''' Increments the 504 stat counters @param request: The scrapy request in the spider ''' for key in self.stats_dict: if key == 'lifetime': unique = request.url + str(time.time()) self.stats_dict...
[ "def", "_increment_504_stat", "(", "self", ",", "request", ")", ":", "for", "key", "in", "self", ".", "stats_dict", ":", "if", "key", "==", "'lifetime'", ":", "unique", "=", "request", ".", "url", "+", "str", "(", "time", ".", "time", "(", ")", ")", ...
Increments the 504 stat counters @param request: The scrapy request in the spider
[ "Increments", "the", "504", "stat", "counters" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/crawler/crawling/log_retry_middleware.py#L149-L161
220,691
istresearch/scrapy-cluster
utils/scutils/redis_throttled_queue.py
RedisThrottledQueue.clear
def clear(self): ''' Clears all data associated with the throttled queue ''' self.redis_conn.delete(self.window_key) self.redis_conn.delete(self.moderate_key) self.queue.clear()
python
def clear(self): ''' Clears all data associated with the throttled queue ''' self.redis_conn.delete(self.window_key) self.redis_conn.delete(self.moderate_key) self.queue.clear()
[ "def", "clear", "(", "self", ")", ":", "self", ".", "redis_conn", ".", "delete", "(", "self", ".", "window_key", ")", "self", ".", "redis_conn", ".", "delete", "(", "self", ".", "moderate_key", ")", "self", ".", "queue", ".", "clear", "(", ")" ]
Clears all data associated with the throttled queue
[ "Clears", "all", "data", "associated", "with", "the", "throttled", "queue" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/utils/scutils/redis_throttled_queue.py#L76-L82
220,692
istresearch/scrapy-cluster
utils/scutils/redis_throttled_queue.py
RedisThrottledQueue.pop
def pop(self, *args): ''' Non-blocking from throttled queue standpoint, tries to return a queue pop request, only will return a request if the given time window has not been exceeded @return: The item if the throttle limit has not been hit, otherwise None ''' ...
python
def pop(self, *args): ''' Non-blocking from throttled queue standpoint, tries to return a queue pop request, only will return a request if the given time window has not been exceeded @return: The item if the throttle limit has not been hit, otherwise None ''' ...
[ "def", "pop", "(", "self", ",", "*", "args", ")", ":", "if", "self", ".", "allowed", "(", ")", ":", "if", "self", ".", "elastic_kick_in", "<", "self", ".", "limit", ":", "self", ".", "elastic_kick_in", "+=", "1", "return", "self", ".", "queue", "."...
Non-blocking from throttled queue standpoint, tries to return a queue pop request, only will return a request if the given time window has not been exceeded @return: The item if the throttle limit has not been hit, otherwise None
[ "Non", "-", "blocking", "from", "throttled", "queue", "standpoint", "tries", "to", "return", "a", "queue", "pop", "request", "only", "will", "return", "a", "request", "if", "the", "given", "time", "window", "has", "not", "been", "exceeded" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/utils/scutils/redis_throttled_queue.py#L90-L104
220,693
istresearch/scrapy-cluster
utils/scutils/redis_throttled_queue.py
RedisThrottledQueue.allowed
def allowed(self): ''' Check to see if the pop request is allowed @return: True means the maximum was not been reached for the current time window, thus allowing what ever operation follows ''' # Expire old keys (hits) expires = time.time() - self.window ...
python
def allowed(self): ''' Check to see if the pop request is allowed @return: True means the maximum was not been reached for the current time window, thus allowing what ever operation follows ''' # Expire old keys (hits) expires = time.time() - self.window ...
[ "def", "allowed", "(", "self", ")", ":", "# Expire old keys (hits)", "expires", "=", "time", ".", "time", "(", ")", "-", "self", ".", "window", "self", ".", "redis_conn", ".", "zremrangebyscore", "(", "self", ".", "window_key", ",", "'-inf'", ",", "expires...
Check to see if the pop request is allowed @return: True means the maximum was not been reached for the current time window, thus allowing what ever operation follows
[ "Check", "to", "see", "if", "the", "pop", "request", "is", "allowed" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/utils/scutils/redis_throttled_queue.py#L112-L157
220,694
istresearch/scrapy-cluster
utils/scutils/redis_throttled_queue.py
RedisThrottledQueue.check_elastic
def check_elastic(self): ''' Checks if we need to break moderation in order to maintain our desired throttle limit @return: True if we need to break moderation ''' if self.elastic and self.elastic_kick_in == self.limit: value = self.redis_conn.zcard(self.wind...
python
def check_elastic(self): ''' Checks if we need to break moderation in order to maintain our desired throttle limit @return: True if we need to break moderation ''' if self.elastic and self.elastic_kick_in == self.limit: value = self.redis_conn.zcard(self.wind...
[ "def", "check_elastic", "(", "self", ")", ":", "if", "self", ".", "elastic", "and", "self", ".", "elastic_kick_in", "==", "self", ".", "limit", ":", "value", "=", "self", ".", "redis_conn", ".", "zcard", "(", "self", ".", "window_key", ")", "if", "self...
Checks if we need to break moderation in order to maintain our desired throttle limit @return: True if we need to break moderation
[ "Checks", "if", "we", "need", "to", "break", "moderation", "in", "order", "to", "maintain", "our", "desired", "throttle", "limit" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/utils/scutils/redis_throttled_queue.py#L159-L170
220,695
istresearch/scrapy-cluster
utils/scutils/redis_throttled_queue.py
RedisThrottledQueue.is_moderated
def is_moderated(self, curr_time, pipe): ''' Tests to see if the moderation limit is not exceeded @return: True if the moderation limit is exceeded ''' # get key, otherwise default the moderate key expired and # we dont care value = pipe.get(self.moderate_key) ...
python
def is_moderated(self, curr_time, pipe): ''' Tests to see if the moderation limit is not exceeded @return: True if the moderation limit is exceeded ''' # get key, otherwise default the moderate key expired and # we dont care value = pipe.get(self.moderate_key) ...
[ "def", "is_moderated", "(", "self", ",", "curr_time", ",", "pipe", ")", ":", "# get key, otherwise default the moderate key expired and", "# we dont care", "value", "=", "pipe", ".", "get", "(", "self", ".", "moderate_key", ")", "if", "value", "is", "None", ":", ...
Tests to see if the moderation limit is not exceeded @return: True if the moderation limit is exceeded
[ "Tests", "to", "see", "if", "the", "moderation", "limit", "is", "not", "exceeded" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/utils/scutils/redis_throttled_queue.py#L172-L190
220,696
istresearch/scrapy-cluster
redis-monitor/plugins/info_monitor.py
InfoMonitor._get_bin
def _get_bin(self, key): ''' Returns a binned dictionary based on redis zscore @return: The sorted dict ''' # keys based on score sortedDict = {} # this doesnt return them in order, need to bin first for item in self.redis_conn.zscan_iter(key): ...
python
def _get_bin(self, key): ''' Returns a binned dictionary based on redis zscore @return: The sorted dict ''' # keys based on score sortedDict = {} # this doesnt return them in order, need to bin first for item in self.redis_conn.zscan_iter(key): ...
[ "def", "_get_bin", "(", "self", ",", "key", ")", ":", "# keys based on score", "sortedDict", "=", "{", "}", "# this doesnt return them in order, need to bin first", "for", "item", "in", "self", ".", "redis_conn", ".", "zscan_iter", "(", "key", ")", ":", "my_item",...
Returns a binned dictionary based on redis zscore @return: The sorted dict
[ "Returns", "a", "binned", "dictionary", "based", "on", "redis", "zscore" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/redis-monitor/plugins/info_monitor.py#L60-L79
220,697
istresearch/scrapy-cluster
redis-monitor/plugins/info_monitor.py
InfoMonitor._build_appid_info
def _build_appid_info(self, master, dict): ''' Builds the appid info object @param master: the master dict @param dict: the dict object received @return: the appid info object ''' master['total_crawlids'] = 0 master['total_pending'] = 0 master['to...
python
def _build_appid_info(self, master, dict): ''' Builds the appid info object @param master: the master dict @param dict: the dict object received @return: the appid info object ''' master['total_crawlids'] = 0 master['total_pending'] = 0 master['to...
[ "def", "_build_appid_info", "(", "self", ",", "master", ",", "dict", ")", ":", "master", "[", "'total_crawlids'", "]", "=", "0", "master", "[", "'total_pending'", "]", "=", "0", "master", "[", "'total_domains'", "]", "=", "0", "master", "[", "'crawlids'", ...
Builds the appid info object @param master: the master dict @param dict: the dict object received @return: the appid info object
[ "Builds", "the", "appid", "info", "object" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/redis-monitor/plugins/info_monitor.py#L81-L150
220,698
istresearch/scrapy-cluster
redis-monitor/plugins/info_monitor.py
InfoMonitor._build_crawlid_info
def _build_crawlid_info(self, master, dict): ''' Builds the crawlid info object @param master: the master dict @param dict: the dict object received @return: the crawlid info object ''' master['total_pending'] = 0 master['total_domains'] = 0 maste...
python
def _build_crawlid_info(self, master, dict): ''' Builds the crawlid info object @param master: the master dict @param dict: the dict object received @return: the crawlid info object ''' master['total_pending'] = 0 master['total_domains'] = 0 maste...
[ "def", "_build_crawlid_info", "(", "self", ",", "master", ",", "dict", ")", ":", "master", "[", "'total_pending'", "]", "=", "0", "master", "[", "'total_domains'", "]", "=", "0", "master", "[", "'appid'", "]", "=", "dict", "[", "'appid'", "]", "master", ...
Builds the crawlid info object @param master: the master dict @param dict: the dict object received @return: the crawlid info object
[ "Builds", "the", "crawlid", "info", "object" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/redis-monitor/plugins/info_monitor.py#L152-L202
220,699
istresearch/scrapy-cluster
redis-monitor/plugins/stop_monitor.py
StopMonitor._purge_crawl
def _purge_crawl(self, spiderid, appid, crawlid): ''' Wrapper for purging the crawlid from the queues @param spiderid: the spider id @param appid: the app id @param crawlid: the crawl id @return: The number of requests purged ''' # purge three times to tr...
python
def _purge_crawl(self, spiderid, appid, crawlid): ''' Wrapper for purging the crawlid from the queues @param spiderid: the spider id @param appid: the app id @param crawlid: the crawl id @return: The number of requests purged ''' # purge three times to tr...
[ "def", "_purge_crawl", "(", "self", ",", "spiderid", ",", "appid", ",", "crawlid", ")", ":", "# purge three times to try to make sure everything is cleaned", "total", "=", "self", ".", "_mini_purge", "(", "spiderid", ",", "appid", ",", "crawlid", ")", "total", "="...
Wrapper for purging the crawlid from the queues @param spiderid: the spider id @param appid: the app id @param crawlid: the crawl id @return: The number of requests purged
[ "Wrapper", "for", "purging", "the", "crawlid", "from", "the", "queues" ]
13aaed2349af5d792d6bcbfcadc5563158aeb599
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/redis-monitor/plugins/stop_monitor.py#L73-L87