Skip to content

Commit

Permalink
[rate limitng] Record errors properly. (#4386)
Browse files Browse the repository at this point in the history
We can't record an error after an exception is raised. Record it first.
  • Loading branch information
jonathanmetzman authored Nov 7, 2024
1 parent cfd2180 commit 56f7d9e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/clusterfuzz/_internal/base/tasks/task_rate_limiting.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
from clusterfuzz._internal.metrics import logs
from clusterfuzz._internal.system import environment

# TODO(metzman): This needs to be done better in utasks where main may return
# an error rather than except. This needs to be handled in postprocess.


def _get_datetime_now():
return datetime.datetime.now()
Expand Down
6 changes: 3 additions & 3 deletions src/clusterfuzz/_internal/bot/tasks/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ def run_command(task_name, task_argument, job_name, uworker_env):
if should_update_task_status(task_name):
if not data_handler.update_task_status(task_state_name,
data_types.TaskState.STARTED):
logs.info('Another instance of "{}" already '
'running, exiting.'.format(task_state_name))
logs.info(f'Another instance of "{task_state_name}" already running, '
'exiting.')
raise AlreadyRunningError

result = None
Expand All @@ -227,10 +227,10 @@ def run_command(task_name, task_argument, job_name, uworker_env):
rate_limiter.record_task(success=False)
except BaseException:
# On any other exceptions, update state to reflect error and re-raise.
rate_limiter.record_task(success=False)
if should_update_task_status(task_name):
data_handler.update_task_status(task_state_name,
data_types.TaskState.ERROR)
rate_limiter.record_task(success=False)
raise
else:
rate_limiter.record_task(success=True)
Expand Down

0 comments on commit 56f7d9e

Please sign in to comment.