rearrange task target logic
@@ -634,23 +634,46 @@ class DistributedTaskQueue():
args['max_backoff_sec'] = queue.max_backoff_seconds
args['max_doublings'] = queue.max_doublings
+ # Override defaults.
+ if request.has_retry_parameters():
+ retry_params = request.retry_parameters()
+ if retry_params.has_retry_limit():
+ args['max_retries'] = retry_params.retry_limit()
+ if retry_params.has_min_backoff_sec():
+ args['min_backoff_sec'] = request.\
+ retry_parameters().min_backoff_sec()
+ if retry_params.has_max_backoff_sec():
+ args['max_backoff_sec'] = request.\
+ retry_parameters().max_backoff_sec()
+ if retry_params.has_max_doublings():
+ args['max_doublings'] = request.\
+ retry_parameters().max_doublings()
+
+ target_url = None
# If we could not get the target from the host, try to get it from the
# queue config.
if queue.target:
target_url = self.get_target_from_queue(app_id, source_info,
queue.target)
+
+ args['url'] = "{target}{url}".format(target=target_url, url=request.url())
+ logger.debug("Old url: {0} New url: {1}".format(request.url(),
+ args['url']))
+ return args
# If we cannot get anything from the queue config, we try the target from
# the request.
- else:
# Try to get the target from host (python sdk will set the target via
# the Host header). Java sdk does not include Host header, so we catch
# the KeyError.
try:
target_url = self.get_target_from_host(app_id, source_info,
headers['Host'])
+ except KeyError:
+ pass
+
# If we cannot get the target from the request we use the source
# module and version.
- except KeyError:
+ if target_url is None:
target_url = "http://{ip}:{port}".format(
ip=self.load_balancer,
port=self.get_module_port(app_id, source_info, target_info=[]))
@@ -659,20 +682,6 @@ class DistributedTaskQueue():
logger.debug("Old url: {0} New url: {1}".format(request.url(),
args['url']))
- # Override defaults.
- if request.has_retry_parameters():
- retry_params = request.retry_parameters()
- if retry_params.has_retry_limit():
- args['max_retries'] = retry_params.retry_limit()
- if retry_params.has_min_backoff_sec():
- args['min_backoff_sec'] = request.\
- retry_parameters().min_backoff_sec()
- if retry_params.has_max_backoff_sec():
- args['max_backoff_sec'] = request.\
- retry_parameters().max_backoff_sec()
- if retry_params.has_max_doublings():
- args['max_doublings'] = request.\
- retry_parameters().max_doublings()
return args
def get_target_from_queue(self, app_id, source_info, target):
