Skip to content

Commit 2fd5805

Browse files
committed
Fix TaskLockedException handling
1 parent 625e1b3 commit 2fd5805

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

sentry_sdk/integrations/huey.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626

2727
try:
2828
from huey.api import Huey, Result, ResultGroup, Task
29-
from huey.exceptions import CancelExecution, RetryTask
29+
from huey.exceptions import CancelExecution, RetryTask, TaskLockedException
3030
except ImportError:
3131
raise DidNotEnable("Huey is not installed")
3232

3333

34-
HUEY_CONTROL_FLOW_EXCEPTIONS = (CancelExecution, RetryTask)
34+
HUEY_CONTROL_FLOW_EXCEPTIONS = (CancelExecution, RetryTask, TaskLockedException)
3535

3636

3737
class HueyIntegration(Integration):

tests/integrations/huey/test_huey.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,34 @@ def retry_task(context):
118118
assert len(huey) == 0
119119

120120

121+
@pytest.mark.parametrize("lock_name", ["lock.a", "lock.b"], ids=["locked", "unlocked"])
122+
def test_task_lock(capture_events, init_huey, lock_name):
123+
huey = init_huey()
124+
125+
task_lock_name = "lock.a"
126+
should_be_locked = task_lock_name == lock_name
127+
128+
@huey.task()
129+
@huey.lock_task(task_lock_name)
130+
def maybe_locked_task():
131+
pass
132+
133+
events = capture_events()
134+
135+
with huey.lock_task(lock_name):
136+
assert huey.is_locked(task_lock_name) == should_be_locked
137+
result = execute_huey_task(huey, maybe_locked_task)
138+
139+
(event,) = events
140+
141+
assert event["transaction"] == "maybe_locked_task"
142+
assert event["tags"]["huey_task_id"] == result.task.id
143+
assert (
144+
event["contexts"]["trace"]["status"] == "aborted" if should_be_locked else "ok"
145+
)
146+
assert len(huey) == 0
147+
148+
121149
def test_huey_enqueue(init_huey, capture_events):
122150
huey = init_huey()
123151

0 commit comments

Comments
 (0)