Skip to content

Commit

Permalink
retry as option
Browse files Browse the repository at this point in the history
  • Loading branch information
digitronik committed Oct 28, 2019
1 parent 70f33b5 commit 61a96dd
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions linkstatus/linkstatus.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from linkstatus.parser import parse_file


def link_status(link, timeout=5):
def link_status(link, timeout):
"""Check link status
Args:
Expand Down Expand Up @@ -49,7 +49,8 @@ def all_files(source, recursive=False):
"-r", "--recursive", is_flag=True, help="Include all files from directories recursively"
)
@click.option("-t", "--timeout", default=5, help="Request timeout (default 4 second)")
def main(source, recursive, timeout):
@click.option("-rt", "--retry", default=2, help="Retry link status (default 2 time)")
def main(source, recursive, timeout, retry):
exit_code = 0
files = all_files(source, recursive=recursive)

Expand All @@ -62,9 +63,9 @@ def main(source, recursive, timeout):
for link in links:
for url in link.urls:
# try two time at least
for _ in range(2):
status, code = link_status(url, timeout)
if status:
for _ in range(int(retry)):
status, code = link_status(url, int(timeout))
if status is True:
break

if status:
Expand Down

0 comments on commit 61a96dd

Please sign in to comment.