diff options
author | martinko | 2013-10-17 14:23:31 +0000 |
---|---|---|
committer | martinko | 2013-10-17 14:23:31 +0000 |
commit | 32307afbcc44950b7678d279abdcce4ffb15703d (patch) | |
tree | de8c921e8077cce655b66f2f06a65dadab436cc3 | |
parent | 7c798fd9a4d6abe07a0dbbecc8082ada77ec0c01 (diff) |
londiste: moved config processing from dispatch to base handler
-rw-r--r-- | python/londiste/handler.py | 14 | ||||
-rw-r--r-- | python/londiste/handlers/dispatch.py | 10 |
2 files changed, 15 insertions, 9 deletions
diff --git a/python/londiste/handler.py b/python/londiste/handler.py index 287ad546..8ce45cff 100644 --- a/python/londiste/handler.py +++ b/python/londiste/handler.py @@ -78,6 +78,7 @@ class BaseHandler: self.fq_dest_table = skytools.quote_fqident(self.dest_table) self.args = args self._check_args (args) + self.conf = self.get_config() def _parse_args_from_doc (self): doc = self.__doc__ or "" @@ -111,6 +112,19 @@ class BaseHandler: if invalid: raise ValueError ("Invalid handler argument: %s" % list(invalid)) + def get_arg (self, name, value_list, default = None): + """ Return arg value or default; also check if value allowed. """ + default = default or value_list[0] + val = type(default)(self.args.get(name, default)) + if val not in value_list: + raise Exception('Bad argument %s value %r' % (name, val)) + return val + + def get_config (self): + """ Process args dict (into handler config). """ + conf = skytools.dbdict() + return conf + def add(self, trigger_arg_list): """Called when table is added. diff --git a/python/londiste/handlers/dispatch.py b/python/londiste/handlers/dispatch.py index 477fd119..2e1c3143 100644 --- a/python/londiste/handlers/dispatch.py +++ b/python/londiste/handlers/dispatch.py @@ -646,7 +646,6 @@ class Dispatcher (ShardHandler): self.dst_curs = None self.pkeys = None # config - self.conf = self.get_config() hdlr_cls = ROW_HANDLERS[self.conf.row_mode] self.row_handler = hdlr_cls(self.log) @@ -675,7 +674,7 @@ class Dispatcher (ShardHandler): def get_config(self): """Processes args dict""" - conf = skytools.dbdict() + conf = ShardHandler.get_config(self) # set table mode conf.table_mode = self.get_arg('table_mode', TABLE_MODES) conf.analyze = self.get_arg('analyze', [0, 1]) @@ -723,13 +722,6 @@ class Dispatcher (ShardHandler): conf.field_map[tmp[0]] = tmp[1] return conf - def get_arg(self, name, value_list, default = None): - default = default or value_list[0] - val = type(default)(self.args.get(name, default)) - if val not in value_list: - raise Exception('Bad argument %s value %r' % (name, val)) - return val - def _validate_hash_key(self): pass # no need for hash key when not sharding |