Skip to content

Commit 71fc01f

Browse files
authored
Merge pull request #69 from wpyoga/discovery-timeout
Expose service discovery timeout to CLI
2 parents c5542d4 + 285809c commit 71fc01f

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

wsdiscovery/cmdline.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from wsdiscovery.publishing import ThreadedWSPublishing as WSPublishing
88
from wsdiscovery.scope import Scope
99
from wsdiscovery.qname import QName
10+
from wsdiscovery.discovery import DEFAULT_DISCOVERY_TIMEOUT
1011

1112
DEFAULT_LOGLEVEL = "INFO"
1213

@@ -43,14 +44,17 @@ def setup_logger(name, loglevel):
4344
type=click.Choice(["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]),
4445
help='Log level')
4546
@click.option('--capture', '-c', nargs=1, type=click.File('w'), help='Capture messages to a file')
46-
def discover(scope, address, port, loglevel, capture):
47+
@click.option('--timeout', '-t', default=DEFAULT_DISCOVERY_TIMEOUT, show_default=True,
48+
type=int, help='Discovery timeout in seconds')
49+
def discover(scope, address, port, loglevel, capture, timeout):
4750
"Discover services using WS-Discovery"
4851

4952
logger = setup_logger("ws-discovery", loglevel)
5053

5154
with discovery(capture) as wsd:
5255
scopes = [Scope(scope)] if scope else []
53-
svcs = wsd.searchServices(scopes=scopes, address=address, port=port)
56+
svcs = wsd.searchServices(scopes=scopes, address=address, port=port,
57+
timeout=timeout)
5458
print("\nDiscovered:\n")
5559
for service in svcs:
5660
url = urlparse(service.getXAddrs()[0])

wsdiscovery/discovery.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
from .threaded import ThreadedNetworking
1212
from .daemon import Daemon
1313

14+
DEFAULT_DISCOVERY_TIMEOUT = 3
15+
1416

1517
class Discovery:
1618
"""networking-agnostic generic remote service discovery mixin"""
@@ -117,8 +119,9 @@ def clearRemoteServices(self):
117119

118120
self._remoteServices.clear()
119121

120-
def searchServices(self, types=None, scopes=None, address=None, port=None, timeout=3):
121-
'search for services given the TYPES and SCOPES in a given TIMEOUT'
122+
def searchServices(self, types=None, scopes=None, address=None, port=None,
123+
timeout=DEFAULT_DISCOVERY_TIMEOUT):
124+
'search for services given the TYPES and SCOPES within a given TIMEOUT'
122125
try:
123126
self._sendProbe(types, scopes, address, port)
124127
except:

0 commit comments

Comments
 (0)