Skip to content
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

Ignore FileNotFoundError when removing the lock file #116

Open
wants to merge 2 commits 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
9 changes: 8 additions & 1 deletion celery_once/backends/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,11 @@ def clear_lock(self, key):
Remove the lock file.
"""
lock_path = self._get_lock_path(key)
os.remove(lock_path)
try:
os.remove(lock_path)
except OSError as exc:
if exc.errno == errno.ENOENT:
# Lock file already deleted
pass
else:
raise exc
11 changes: 11 additions & 0 deletions tests/unit/backends/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,14 @@ def test_file_clear_lock(backend, mocker):
assert remove_mock.call_count == 1
assert remove_mock.call_args[0] == (expected_lock_path,)
assert ret is None


def test_file_clear_lock_already_removed(backend, mocker):
key = 'test.task.key'
mocker.patch('celery_once.backends.file.os.remove',
side_effect=OSError(errno.ENOENT, 'error'))
expected_lock_path = os.path.join(TEST_LOCATION,
key_to_lock_name(key))
ret = backend.clear_lock(key)

assert ret is None