Skip to content

fix(taskworker) Add shim for __start_time #92223

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions src/sentry/taskworker/workerchild.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,13 @@ def _execute_activation(task_func: Task[Any, Any], activation: TaskActivation) -
)
span.set_data(SPANDATA.MESSAGING_SYSTEM, "taskworker")

# TODO(taskworker) remove this when doing cleanup
# The `__start_time` parameter is spliced into task parameters by
# sentry.celery.SentryTask._add_metadata and needs to be removed
# from kwargs like sentry.tasks.base.instrumented_task does.
if "__start_time" in kwargs:
kwargs.pop("__start_time")

try:
task_func(*args, **kwargs)
transaction.set_status(SPANSTATUS.OK)
Expand Down
29 changes: 29 additions & 0 deletions tests/sentry/taskworker/test_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,35 @@ def test_child_process_complete(mock_capture_checkin) -> None:
assert mock_capture_checkin.call_count == 0


@pytest.mark.django_db
def test_child_process_remove_start_time_kwargs() -> None:
activation = TaskActivation(
id="6789",
taskname="examples.will_retry",
namespace="examples",
parameters='{"args": ["stuff"], "kwargs": {"__start_time": 123}}',
processing_deadline_duration=100000,
)
todo: queue.Queue[TaskActivation] = queue.Queue()
processed: queue.Queue[ProcessingResult] = queue.Queue()
shutdown = Event()

todo.put(activation)
child_process(
todo,
processed,
shutdown,
max_task_count=1,
processing_pool_name="test",
process_type="fork",
)

assert todo.empty()
result = processed.get()
assert result.task_id == activation.id
assert result.status == TASK_ACTIVATION_STATUS_COMPLETE


@pytest.mark.django_db
@mock.patch("sentry.usage_accountant.record")
def test_child_process_complete_record_usage(mock_record: mock.Mock) -> None:
Expand Down
Loading