Skip to content

populate task name cache from worker inspect#32

Merged
aviator-app[bot] merged 2 commits into
mainfrom
populate-task-name-cache-from-worker-inspect
May 4, 2026
Merged

populate task name cache from worker inspect#32
aviator-app[bot] merged 2 commits into
mainfrom
populate-task-name-cache-from-worker-inspect

Conversation

@tulioz

@tulioz tulioz commented May 1, 2026

Copy link
Copy Markdown
Contributor

keeps the event-driven runtime histogram from bucketing tasks as (UNKNOWN) after celerymon restarts, since the worker watcher already has the names from inspect.active

@aviator-app

aviator-app Bot commented May 1, 2026

Copy link
Copy Markdown

Current Aviator status

Aviator will automatically update this comment as the status of the PR changes.
Comment /aviator refresh to force Aviator to re-examine your PR (or learn about other /aviator commands).

This PR was merged using Aviator.


See the real-time status of this PR on the Aviator webapp.
Use the Aviator Chrome Extension to see the status of your PR within GitHub.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces thread-safe task name management in EventWatcher by implementing a lock and refactoring name resolution. WorkerWatcher is updated to populate this cache during its periodic updates, and the project version is bumped to 0.1.11. Feedback suggests optimizing EventWatcher.on_event to avoid redundant lock acquisitions when the task name is already present in the event data.

Comment thread celerymon/event_watcher.py Outdated
Comment on lines +174 to +177
if "name" in event:
self._task_names_by_uuid.pop(uuid, None)
self._task_names_by_uuid[uuid] = event["name"]
while len(self._task_names_by_uuid) > self._TASK_NAMES_CACHE_LIMIT:
self._task_names_by_uuid.popitem(last=False)
self.record_task_name(uuid, event["name"])

task_name = self._task_names_by_uuid.get(uuid, "(UNKNOWN)")
task_name = self._resolve_task_name(uuid)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current implementation acquires the _task_names_by_uuid_lock twice when a task name is present in the event: once during record_task_name and again during _resolve_task_name. This can be optimized by using the name directly from the event when available, avoiding the second lock acquisition and dictionary lookup.

Suggested change
if "name" in event:
self._task_names_by_uuid.pop(uuid, None)
self._task_names_by_uuid[uuid] = event["name"]
while len(self._task_names_by_uuid) > self._TASK_NAMES_CACHE_LIMIT:
self._task_names_by_uuid.popitem(last=False)
self.record_task_name(uuid, event["name"])
task_name = self._task_names_by_uuid.get(uuid, "(UNKNOWN)")
task_name = self._resolve_task_name(uuid)
if "name" in event:
task_name = event["name"]
self.record_task_name(uuid, task_name)
else:
task_name = self._resolve_task_name(uuid)

@tulioz tulioz force-pushed the populate-task-name-cache-from-worker-inspect branch 2 times, most recently from c9cdc7d to f46f738 Compare May 1, 2026 23:23
@tulioz tulioz force-pushed the populate-task-name-cache-from-worker-inspect branch from f46f738 to cd078cf Compare May 2, 2026 00:06
@tulioz tulioz requested a review from jainankit May 2, 2026 00:06
Comment thread celerymon/event_watcher.py
@aviator-app aviator-app Bot merged commit ed4356b into main May 4, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants