Skip to content

Commit cbc28f7

Browse files
Fix task polling and test sleep mock
1 parent bdf546f commit cbc28f7

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

src/conductor/client/automator/task_runner.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,15 @@ def __poll_task(self) -> Task:
9393
)
9494
if auth_exception.invalid_token:
9595
logger.error(
96-
"Failed to poll task: %s; reason: invalid auth token", task_definition_name
96+
"Failed to poll task: %s; reason: invalid auth token",
97+
task_definition_name,
9798
)
9899
else:
99100
logger.error(
100-
"Failed to poll task: %s; status: %s - {auth_exception.error_code}", task_definition_name, auth_exception.status, auth_exception.error_code
101+
"Failed to poll task: %s; status: %s - %s",
102+
task_definition_name,
103+
auth_exception.status,
104+
auth_exception.error_code,
101105
)
102106
return None
103107
except ApiException as e:
@@ -106,11 +110,20 @@ def __poll_task(self) -> Task:
106110
task_definition_name, type(e)
107111
)
108112
logger.error(
109-
"Failed to poll task for: %s, reason: %s",
113+
"Failed to poll task: %s, reason: %s, code: %s",
110114
task_definition_name,
111-
traceback.format_exc(),
115+
e.reason,
116+
e.code,
112117
)
113118
return None
119+
except Exception as e:
120+
if self.metrics_collector is not None:
121+
self.metrics_collector.increment_task_poll_error(
122+
task_definition_name, type(e)
123+
)
124+
logger.error("Failed to poll task: %s; reason: %s", task_definition_name, e)
125+
return None
126+
114127
if task is not None:
115128
logger.debug(
116129
"Polled task: %s; worker_id: %s; domain: %s",

tests/unit/automator/test_async_task_runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ async def test_update_task_with_invalid_task_result():
279279

280280
@pytest.mark.asyncio
281281
async def test_update_task_with_faulty_task_api(mocker):
282-
mocker.patch("time.sleep", return_value=None)
282+
mocker.patch("asyncio.sleep", return_value=None)
283283
mocker.patch.object(TaskResourceApiAdapter, "update_task", side_effect=Exception())
284284
task_runner = get_valid_task_runner()
285285
task_result = get_valid_task_result()

0 commit comments

Comments
 (0)