Skip to content

Commit

Permalink
Added 'requests' default timeout interval
Browse files Browse the repository at this point in the history
  • Loading branch information
Milos Buncic committed Sep 26, 2017
1 parent abe996c commit 80e7573
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ k8s-deployer HTTP API

About
---
Deploy Kubernetes service and insert retrieved information into Consul K/V store
Deploy Kubernetes service and insert retrieved information into the Consul K/V store

![kubernetes-external-load-balancing](./images/kubernetes-external-load-balancing.png)

Expand Down
10 changes: 6 additions & 4 deletions k8s-deployer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


__prog__ = os.path.splitext(os.path.basename(__file__))[0]
__version__ = 'v0.1.2'
__version__ = 'v0.1.3'
__author__ = 'Milos Buncic'
__date__ = '2017/03/20'
__description__ = 'Kubernetes deployer API with Consul registration'
Expand Down Expand Up @@ -51,7 +51,7 @@ def load_config(config_file):
sys.exit(1)


def req(method, url, headers={}, payload=None, status_code=False):
def req(method, url, headers={}, payload=None, status_code=False, timeout=30):
"""
Request function with error handlers (output: dict)
"""
Expand All @@ -67,13 +67,15 @@ def req(method, url, headers={}, payload=None, status_code=False):
try:
if method in ['GET', 'DELETE']:
r = requests.request(
method, url, headers=pass_headers, verify=False
method, url,
headers=pass_headers, timeout=timeout, verify=False
)
elif method in ['POST', 'PUT', 'PATCH']:
### built-in json parameter does not support pretty-printing
# r = requests.request(method, url, json=payload)
r = requests.request(
method, url, headers=pass_headers, verify=False,
method, url,
headers=pass_headers, timeout=timeout, verify=False,
data=json.dumps(
payload, indent=4, separators=(',', ': ')
)
Expand Down

0 comments on commit 80e7573

Please sign in to comment.