Skip to content

Commit ef24a55

Browse files
authored
Merge pull request #450 from rstudio/tdstein/442
Adds Human Friendly Error Message For Task Timeouts
2 parents 356c866 + 577d164 commit ef24a55

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

rsconnect/api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from .metadata import ServerStore, AppStore
2929
from .exception import RSConnectException
3030
from .bundle import _default_title, fake_module_file_from_directory
31-
from .timeouts import get_task_timeout
31+
from .timeouts import get_task_timeout, get_task_timeout_help_message
3232

3333

3434
class AbstractRemoteServer:
@@ -313,7 +313,7 @@ def wait_for_task(
313313
time_slept = 0
314314
while True:
315315
if (time.time() - start_time) > timeout:
316-
raise RSConnectException("Task timed out after %d seconds" % timeout)
316+
raise RSConnectException(get_task_timeout_help_message(timeout))
317317
elif abort_func():
318318
raise RSConnectException("Task aborted.")
319319

@@ -1195,7 +1195,7 @@ def wait_until_task_is_successful(self, task_id, timeout=get_task_timeout()):
11951195
time.sleep(2)
11961196

11971197
if not finished:
1198-
raise RSConnectException("Application deployment timed out.")
1198+
raise RSConnectException(get_task_timeout_help_message(timeout))
11991199

12001200
if status != "success":
12011201
raise RSConnectException("Application deployment failed with error: {}".format(error))

rsconnect/timeouts.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import os
2+
import textwrap
3+
24
from typing import Union
35

46
from rsconnect.exception import RSConnectException
@@ -70,3 +72,18 @@ def get_task_timeout() -> int:
7072
raise RSConnectException(f"'CONNECT_TASK_TIMEOUT' is set to '{timeout}'. The value must be a positive integer.")
7173

7274
return timeout
75+
76+
77+
def get_task_timeout_help_message(timeout=get_task_timeout()) -> str:
78+
"""Gets a human friendly help message for adjusting the task timeout value."""
79+
80+
return f"The task timed out after {timeout} seconds." + textwrap.dedent(
81+
f"""
82+
83+
You may try increasing the task timeout value using the {_CONNECT_TASK_TIMEOUT_KEY} environment variable. The default value is {_CONNECT_TASK_TIMEOUT_DEFAULT_VALUE} seconds. The current value is {get_task_timeout()} seconds.
84+
85+
Example:
86+
87+
CONNECT_TASK_TIMEOUT={_CONNECT_TASK_TIMEOUT_DEFAULT_VALUE} rsconnect deploy api --server <your-server> --api-key <your-api-key> ./
88+
""" # noqa: E501
89+
)

tests/test_timeouts.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from unittest.mock import patch
55

66
from rsconnect.exception import RSConnectException
7-
from rsconnect.timeouts import get_request_timeout, get_task_timeout
7+
from rsconnect.timeouts import get_request_timeout, get_task_timeout, get_task_timeout_help_message
88

99

1010
class GetRequestTimeoutTestCase(TestCase):
@@ -56,3 +56,11 @@ def test_get_negative_timeout_from_environment(self):
5656
with patch.dict(os.environ, {"CONNECT_TASK_TIMEOUT": "-24"}):
5757
with self.assertRaises(RSConnectException):
5858
get_task_timeout()
59+
60+
class GetTaskTimeoutHelpMessageTestCase(TestCase):
61+
def test_get_task_timeout_help_message(self):
62+
res = get_task_timeout_help_message(1)
63+
self.assertTrue("The task timed out after 1 seconds." in res)
64+
self.assertTrue("You may try increasing the task timeout value using the CONNECT_TASK_TIMEOUT environment variable." in res) # noqa: E501
65+
self.assertTrue("The default value is 86400 seconds." in res)
66+
self.assertTrue("The current value is 86400 seconds." in res)

0 commit comments

Comments
 (0)