Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add config default_task_max_retries #39

Merged
merged 1 commit into from Jun 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions data_integration/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ def default_db_alias() -> str:
return 'dwh-etl'


def default_task_max_retries():
"""How many times a task is retried when it fails by default """
return 0


def first_date() -> datetime.date:
"""Ignore data before this date"""
return datetime.date(2000, 1, 1)
Expand Down
5 changes: 3 additions & 2 deletions data_integration/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,10 +373,11 @@ def run(self):
try:
while True:
if not self.task.run():
if attempt < self.task.max_retries:
max_retries = self.task.max_retries or config.default_task_max_retries()
if attempt < max_retries:
attempt += 1
delay = pow(2, attempt + 2)
logger.log(message=f'Retry {attempt}/{self.task.max_retries} in {delay} seconds',
logger.log(message=f'Retry {attempt}/{max_retries} in {delay} seconds',
is_error=True, format=logger.Format.ITALICS)
time.sleep(delay)
else:
Expand Down
2 changes: 1 addition & 1 deletion data_integration/pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def html_doc_items(self) -> [(str, str)]:


class Task(Node):
def __init__(self, id: str, description: str, commands: [Command] = None, max_retries: int = 0) -> None:
def __init__(self, id: str, description: str, commands: [Command] = None, max_retries: int = None) -> None:
super().__init__(id, description)
self.commands = []
self.max_retries = max_retries
martin-loetzsch marked this conversation as resolved.
Show resolved Hide resolved
Expand Down